hal_presenter 1.4.0 → 1.5.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 +0 -0
- data.tar.gz.sig +0 -0
- data/lib/hal_presenter/links.rb +6 -9
- data/lib/hal_presenter/serializer.rb +26 -9
- metadata +2 -2
- metadata.gz.sig +1 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 306b8de363e5da5cb14c573bf44e7c6cceefd0d0a050dba2a859da94429722aa
|
4
|
+
data.tar.gz: 42d74e04e03c0b4705023385e3bd9ddff1d3d70f638536f40143a3ab47c30e56
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44aa0f45829620c8d2b26283503b0906df6201d0d9ec7f38b692c02aabb4a3418c953d0ca4385f112650bd88fa7b654a8f11a7731feab332f45e35fd71042515
|
7
|
+
data.tar.gz: 82d4afdb641c4299cb9e7c56c18b3ef6b3c7e01234e10f230e0a77d0ae15966c855460774ffd3d2754de763dae00cfd10215842086d6ee7c6b7127dc91e09cbc
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/hal_presenter/links.rb
CHANGED
@@ -46,15 +46,13 @@ module HALPresenter
|
|
46
46
|
href = value(resource, options)
|
47
47
|
return {} unless href
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
49
|
+
{href: HALPresenter.href(href)}.tap do |hash|
|
50
|
+
hash[:type] = type if type
|
51
|
+
hash[:deprecation] = deprecation if deprecation
|
52
|
+
hash[:profile] = profile if profile
|
53
|
+
hash[:title] = title if title
|
54
|
+
hash[:templated] = templated if templated
|
55
55
|
end
|
56
|
-
|
57
|
-
{rel => hash}
|
58
56
|
end
|
59
57
|
end
|
60
58
|
|
@@ -68,7 +66,6 @@ module HALPresenter
|
|
68
66
|
end
|
69
67
|
|
70
68
|
kwargs[:context] ||= self
|
71
|
-
links.delete_if { |link| link.rel == rel }
|
72
69
|
Link.new(rel, value, **kwargs, &block).tap do |link|
|
73
70
|
links << link
|
74
71
|
end
|
@@ -6,21 +6,24 @@ module HALPresenter
|
|
6
6
|
|
7
7
|
module ClassMethods
|
8
8
|
def to_hal(resource, options = {})
|
9
|
-
raise Serializer::Error, "Resource is nil" if resource.nil?
|
10
9
|
options = options.dup
|
11
|
-
presenter
|
12
|
-
presenter ||= HALPresenter.lookup_presenter(resource)
|
13
|
-
raise Serializer::Error, "No presenter for #{resource.class}" unless presenter
|
14
|
-
presenter.to_hal(resource, options)
|
10
|
+
presenter!(resource, options).to_hal(resource, options)
|
15
11
|
end
|
16
12
|
|
17
13
|
def to_collection(resources, options = {})
|
18
|
-
raise Serializer::Error, "resources is nil" if resources.nil?
|
19
14
|
options = options.dup
|
15
|
+
presenter!(resources, options).to_collection(resources, options)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def presenter!(resources, options = {})
|
21
|
+
raise Serializer::Error, "resources is nil" if resources.nil?
|
20
22
|
presenter = options.delete(:presenter)
|
21
23
|
presenter ||= HALPresenter.lookup_presenter(resources)
|
22
24
|
raise Serializer::Error, "No presenter for #{resources.first.class}" unless presenter
|
23
|
-
|
25
|
+
|
26
|
+
presenter
|
24
27
|
end
|
25
28
|
end
|
26
29
|
|
@@ -37,6 +40,8 @@ module HALPresenter
|
|
37
40
|
options[:_depth] ||= 0
|
38
41
|
hash = to_hash(resource, options)
|
39
42
|
move_curies_to_root! hash
|
43
|
+
return hash if options[:as_hash]
|
44
|
+
|
40
45
|
JSON.generate(hash)
|
41
46
|
end
|
42
47
|
|
@@ -51,6 +56,8 @@ module HALPresenter
|
|
51
56
|
options[:_depth] ||= 0
|
52
57
|
hash = to_collection_hash(resources, options)
|
53
58
|
move_curies_to_root! hash
|
59
|
+
return hash if options[:as_hash]
|
60
|
+
|
54
61
|
JSON.generate(hash)
|
55
62
|
end
|
56
63
|
|
@@ -133,9 +140,19 @@ module HALPresenter
|
|
133
140
|
|
134
141
|
def _serialize_links(links, curies, resource, policy, options)
|
135
142
|
serialized = links.each_with_object({}) do |link, hash|
|
143
|
+
rel = link.rel
|
136
144
|
next unless link.nested_depth_ok? options[:_depth]
|
137
|
-
next if policy && !policy.link?(
|
138
|
-
|
145
|
+
next if policy && !policy.link?(rel)
|
146
|
+
|
147
|
+
link_hash = link.to_h(resource, options)
|
148
|
+
next if link_hash.empty?
|
149
|
+
|
150
|
+
if hash.key? rel
|
151
|
+
hash[rel] = [hash[rel]] unless hash[rel].is_a? Array
|
152
|
+
hash[rel] << link_hash
|
153
|
+
else
|
154
|
+
hash.merge!(rel => link_hash)
|
155
|
+
end
|
139
156
|
end
|
140
157
|
curies = _serialize_curies(curies, resource, options)
|
141
158
|
serialized[:curies] = curies if curies.any?
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hal_presenter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sammy Henningsson
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
ZMhjYR7sRczGJx+GxGU2EaR0bjRsPVlC4ywtFxoOfRG3WaJcpWGEoAoMJX6Z0bRv
|
31
31
|
M40=
|
32
32
|
-----END CERTIFICATE-----
|
33
|
-
date:
|
33
|
+
date: 2020-01-18 00:00:00.000000000 Z
|
34
34
|
dependencies:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: rake
|
metadata.gz.sig
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
K�
|
2
|
-
ĬEig����F�Z��}(�uVUڠ�z�uz�6p(-Jz��n��5d�͚���<�T�������- /�E�)#�Xy���x8�4*+)&W�&Q��T(.H��B�#�V�g����M�`$�2m�;�~
|
1
|
+
L�oHk�O��_�Jƹ�Ȟ���1U�X��j9Q��lrı6z��eX&���UF���lR��}Am5��@����`!0n�9O_���/}l"Y��>+��a;���v�� ˂���f��S���7�<��r���p��4�n�3�"쵺�a�K��]��u�G&���n���5��:�Q#l�"���,>e�HTކHX@%g�F�Jt�>��N�M٩��*_)���M8P�dlQ�}߉�Pa�"%�v
|