hal_presenter 1.6.0 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +1 -2
- data/lib/hal_presenter/deserializer.rb +5 -6
- data/lib/hal_presenter/links.rb +22 -19
- data/lib/hal_presenter/model.rb +24 -24
- data/lib/hal_presenter/pagination.rb +1 -4
- data/lib/hal_presenter/serializer.rb +19 -20
- data.tar.gz.sig +0 -0
- metadata +36 -36
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d44a7bd34475ea7e7187811e8e3d4447430835e6327440a714315477b8307f2
|
4
|
+
data.tar.gz: fa9bede97a583685589e2cea815be591bbb90c45034baf4697717fb06adc5f2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df06bf35cd4e145679e0cf40b48d6823e8caa6b72954e1cdf3383797d6925045010ac993aceca7ef29affac6a1b46468ef2c444be6da0a3a60ddae0df2b56b72
|
7
|
+
data.tar.gz: dfdf0f1603bffe9be19f803d18a6e31d83ba9ac0bcf5bdbf566760f29afec09945da2c86f33b4f676afa7ac5b0c6cf9ea63492f3a4146361c6dc32b7fa9de161
|
checksums.yaml.gz.sig
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
|
2
|
-
�i�ǻ���4���2Xx��"S6�A|�PU��5Y�{�;�]� [������Q�ա߲ ~�Ǟ"�4k1�E�F��FK
|
1
|
+
��Х��N�E��t��b/+���3�6���ȇ�W�Z�%�� ʐ�2//zF�� $K��ɏ2n��s�fӃ�?@��a�I�`��&�ve$�_�f)L4�"�h������n�D��~��̗�fd;���(y��KK�������K��y�8W�40�7��0���=�#�;j�`V� �c����5��k�nO=:o0Jb��O(����M���~H���FU.,�X�Ś�if���fϱg!P�`
|
@@ -1,13 +1,12 @@
|
|
1
1
|
require 'json'
|
2
2
|
|
3
3
|
module HALPresenter
|
4
|
-
module ClassMethods
|
5
|
-
def from_hal(presenter, payload, resource = nil)
|
6
|
-
presenter.from_hal(payload, resource)
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
4
|
module Deserializer
|
5
|
+
module ClassMethods
|
6
|
+
def from_hal(presenter, payload, resource = nil)
|
7
|
+
presenter.from_hal(payload, resource)
|
8
|
+
end
|
9
|
+
end
|
11
10
|
|
12
11
|
class Error < StandardError; end
|
13
12
|
|
data/lib/hal_presenter/links.rb
CHANGED
@@ -2,21 +2,20 @@ require 'hal_presenter/property'
|
|
2
2
|
require 'hal_presenter/super_init'
|
3
3
|
|
4
4
|
module HALPresenter
|
5
|
+
module Links
|
6
|
+
include SuperInit
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
module ClassMethods
|
9
|
+
def base_href=(base)
|
10
|
+
@base_href = base&.sub(%r(/*$), '')
|
11
|
+
end
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
def href(href)
|
14
|
+
return href if (@base_href ||= '').empty?
|
15
|
+
return href if href =~ %r(\A(\w+://)?[^/])
|
16
|
+
@base_href + href
|
17
|
+
end
|
15
18
|
end
|
16
|
-
end
|
17
|
-
|
18
|
-
module Links
|
19
|
-
include SuperInit
|
20
19
|
|
21
20
|
class Link < HALPresenter::Property
|
22
21
|
attr_reader :type, :deprecation, :profile, :title
|
@@ -29,6 +28,7 @@ module HALPresenter
|
|
29
28
|
@deprecation = kwargs[:deprecation].freeze
|
30
29
|
@profile = kwargs[:profile].freeze
|
31
30
|
@title = kwargs[:title].freeze
|
31
|
+
@templated = kwargs[:templated].freeze
|
32
32
|
|
33
33
|
curie = kwargs[:curie].to_s
|
34
34
|
rel = [curie, rel.to_s].join(':') unless curie.empty?
|
@@ -46,13 +46,16 @@ module HALPresenter
|
|
46
46
|
href = value(resource, options)
|
47
47
|
return {} unless href
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
49
|
+
values = href.respond_to?(:to_h) ? href.to_h : {}
|
50
|
+
values[:href] = HALPresenter.href(values[:href] || href)
|
51
|
+
|
52
|
+
{
|
53
|
+
type: type,
|
54
|
+
deprecation: deprecation,
|
55
|
+
profile: profile,
|
56
|
+
title: title,
|
57
|
+
templated: templated
|
58
|
+
}.compact.merge(values)
|
56
59
|
end
|
57
60
|
end
|
58
61
|
|
data/lib/hal_presenter/model.rb
CHANGED
@@ -1,36 +1,36 @@
|
|
1
1
|
module HALPresenter
|
2
2
|
@presenters = {}
|
3
3
|
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
module Model
|
5
|
+
module ClassMethods
|
6
|
+
def register(model:, presenter:)
|
7
|
+
return unless presenter && model
|
8
|
+
@presenters[presenter] = model
|
9
|
+
end
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
def unregister(presenter)
|
12
|
+
@presenters.delete_if { |d,_| d == presenter }
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
def lookup_model(presenter)
|
16
|
+
@presenters[presenter]
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
def lookup_presenter(model)
|
20
|
+
presenters = lookup_presenters(model)
|
21
|
+
return presenters.last unless presenters.empty?
|
22
|
+
lookup_presenters(model.first).last if model.respond_to? :first
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
def lookup_presenters(model)
|
26
|
+
clazz = model.is_a?(Class) ? model : model.class
|
27
|
+
presenters = @presenters.select { |_d, m| m == clazz }.keys
|
28
|
+
return presenters unless presenters.empty?
|
29
|
+
return [] unless clazz < BasicObject
|
30
|
+
lookup_presenters(clazz.superclass)
|
31
|
+
end
|
30
32
|
end
|
31
|
-
end
|
32
33
|
|
33
|
-
module Model
|
34
34
|
def self.included(base)
|
35
35
|
base.extend ClassMethods
|
36
36
|
end
|
@@ -3,31 +3,29 @@ require 'hal_presenter/pagination'
|
|
3
3
|
require 'hal_presenter/curie_collection'
|
4
4
|
|
5
5
|
module HALPresenter
|
6
|
+
module Serializer
|
7
|
+
module ClassMethods
|
8
|
+
def to_hal(resource, **options)
|
9
|
+
options = options.dup
|
10
|
+
presenter!(resource, **options).to_hal(resource, **options)
|
11
|
+
end
|
6
12
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
def to_collection(resources, **options)
|
14
|
-
options = options.dup
|
15
|
-
presenter!(resources, options).to_collection(resources, options)
|
16
|
-
end
|
13
|
+
def to_collection(resources, **options)
|
14
|
+
options = options.dup
|
15
|
+
presenter!(resources, **options).to_collection(resources, **options)
|
16
|
+
end
|
17
17
|
|
18
|
-
|
18
|
+
private
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
def presenter!(resources, **options)
|
21
|
+
raise Serializer::Error, "resources is nil" if resources.nil?
|
22
|
+
presenter = options.delete(:presenter)
|
23
|
+
presenter ||= HALPresenter.lookup_presenter(resources)
|
24
|
+
raise Serializer::Error, "No presenter for #{resources.first.class}" unless presenter
|
25
25
|
|
26
|
-
|
26
|
+
presenter
|
27
|
+
end
|
27
28
|
end
|
28
|
-
end
|
29
|
-
|
30
|
-
module Serializer
|
31
29
|
|
32
30
|
class Error < StandardError; end
|
33
31
|
|
@@ -75,6 +73,7 @@ module HALPresenter
|
|
75
73
|
end
|
76
74
|
|
77
75
|
def to_collection_hash(resources, options)
|
76
|
+
resources ||= []
|
78
77
|
policy = policy_for(nil, options)
|
79
78
|
properties = collection_properties
|
80
79
|
attributes = properties.attributes
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hal_presenter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sammy Henningsson
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain:
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
13
|
MIIDVjCCAj6gAwIBAgIBATANBgkqhkiG9w0BAQsFADAqMSgwJgYDVQQDDB9zYW1t
|
14
|
-
|
15
|
-
|
14
|
+
eS5oZW5uaW5nc3Nvbi9EQz1oZXkvREM9Y29tMB4XDTIyMDEzMTIwNTQxMloXDTI0
|
15
|
+
MDEzMTIwNTQxMlowKjEoMCYGA1UEAwwfc2FtbXkuaGVubmluZ3Nzb24vREM9aGV5
|
16
16
|
L0RDPWNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAK+SDC1mfyhu
|
17
17
|
cJ6Va21rIHUGscEtQrdvyBqxFG1s2TgPMAv4RbqwdJVPa7kjtbCzslADlUE1oru2
|
18
18
|
C+rcJsMtVGX02ukMIPHT1OjTyy0/EMqLqSy3WeRI8APyDSxCVbe+h5BMf3zZnYfd
|
@@ -22,93 +22,93 @@ cert_chain:
|
|
22
22
|
nIxTSJpPr2cCAwEAAaOBhjCBgzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNV
|
23
23
|
HQ4EFgQUukjj1Cd2ea6IOHDLZe0ymzs2jWkwJAYDVR0RBB0wG4EZc2FtbXkuaGVu
|
24
24
|
bmluZ3Nzb25AaGV5LmNvbTAkBgNVHRIEHTAbgRlzYW1teS5oZW5uaW5nc3NvbkBo
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
25
|
+
ZXkuY29tMA0GCSqGSIb3DQEBCwUAA4IBAQCNUrjx1+L5W9R5O5MF3fnnNIyxOXGa
|
26
|
+
qzqpmXpTd7pHUGvSzVxYM/NIkUHSSPyxLAG+RYMPJHjDOSzhLmOUbgpfOsQ8sqUP
|
27
|
+
plABBC03e/+oDwFwlHefonil+sp/AOT9TYZJQbShjKt3/X+VGzjtujJZwvKgiiP0
|
28
|
+
Ht5Q4dvW1ZqUZgvXdYM1LnCX7I3WjoRyhOwdSlaEz5gnD+KYewHiiByK1Jv2n0PG
|
29
|
+
DVzXaUnsmwP+jQ1PkDa5q8ibBzMd2c6Hmm87UDqPxZtML0bF9SjrpbyLMjwtXaMA
|
30
|
+
WDPp0ajpdUZ9GPHsrVNYXiOfQIqcmlmpYVsH1o7vuneUIcIDMrnMDChh
|
31
31
|
-----END CERTIFICATE-----
|
32
|
-
date:
|
32
|
+
date: 2022-01-31 00:00:00.000000000 Z
|
33
33
|
dependencies:
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
35
|
name: rake
|
36
36
|
requirement: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '10.0'
|
41
38
|
- - "~>"
|
42
39
|
- !ruby/object:Gem::Version
|
43
40
|
version: '12.0'
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '10.0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
46
|
version_requirements: !ruby/object:Gem::Requirement
|
47
47
|
requirements:
|
48
|
-
- - ">="
|
49
|
-
- !ruby/object:Gem::Version
|
50
|
-
version: '10.0'
|
51
48
|
- - "~>"
|
52
49
|
- !ruby/object:Gem::Version
|
53
50
|
version: '12.0'
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '10.0'
|
54
54
|
- !ruby/object:Gem::Dependency
|
55
55
|
name: activesupport
|
56
56
|
requirement: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
|
-
- - ">="
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version: '4.0'
|
61
58
|
- - "~>"
|
62
59
|
- !ruby/object:Gem::Version
|
63
60
|
version: '5.0'
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '4.0'
|
64
64
|
type: :development
|
65
65
|
prerelease: false
|
66
66
|
version_requirements: !ruby/object:Gem::Requirement
|
67
67
|
requirements:
|
68
|
-
- - ">="
|
69
|
-
- !ruby/object:Gem::Version
|
70
|
-
version: '4.0'
|
71
68
|
- - "~>"
|
72
69
|
- !ruby/object:Gem::Version
|
73
70
|
version: '5.0'
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '4.0'
|
74
74
|
- !ruby/object:Gem::Dependency
|
75
75
|
name: minitest
|
76
76
|
requirement: !ruby/object:Gem::Requirement
|
77
77
|
requirements:
|
78
|
-
- - ">="
|
79
|
-
- !ruby/object:Gem::Version
|
80
|
-
version: '5.0'
|
81
78
|
- - "~>"
|
82
79
|
- !ruby/object:Gem::Version
|
83
80
|
version: '5.10'
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '5.0'
|
84
84
|
type: :development
|
85
85
|
prerelease: false
|
86
86
|
version_requirements: !ruby/object:Gem::Requirement
|
87
87
|
requirements:
|
88
|
-
- - ">="
|
89
|
-
- !ruby/object:Gem::Version
|
90
|
-
version: '5.0'
|
91
88
|
- - "~>"
|
92
89
|
- !ruby/object:Gem::Version
|
93
90
|
version: '5.10'
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '5.0'
|
94
94
|
- !ruby/object:Gem::Dependency
|
95
95
|
name: byebug
|
96
96
|
requirement: !ruby/object:Gem::Requirement
|
97
97
|
requirements:
|
98
|
-
- - "
|
98
|
+
- - "~>"
|
99
99
|
- !ruby/object:Gem::Version
|
100
100
|
version: '9.0'
|
101
|
-
- - "
|
101
|
+
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '9.0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- - "
|
108
|
+
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '9.0'
|
111
|
-
- - "
|
111
|
+
- - ">="
|
112
112
|
- !ruby/object:Gem::Version
|
113
113
|
version: '9.0'
|
114
114
|
- !ruby/object:Gem::Dependency
|
@@ -183,7 +183,7 @@ homepage: https://github.com/sammyhenningsson/hal_presenter
|
|
183
183
|
licenses:
|
184
184
|
- MIT
|
185
185
|
metadata: {}
|
186
|
-
post_install_message:
|
186
|
+
post_install_message:
|
187
187
|
rdoc_options: []
|
188
188
|
require_paths:
|
189
189
|
- lib
|
@@ -198,8 +198,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
198
198
|
- !ruby/object:Gem::Version
|
199
199
|
version: '0'
|
200
200
|
requirements: []
|
201
|
-
rubygems_version: 3.
|
202
|
-
signing_key:
|
201
|
+
rubygems_version: 3.1.6
|
202
|
+
signing_key:
|
203
203
|
specification_version: 4
|
204
204
|
summary: JSON HAL serializer
|
205
205
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|