hal_presenter 0.4.0 → 0.4.1
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/collection.rb +18 -4
- data/lib/hal_presenter/embedded.rb +2 -2
- data/lib/hal_presenter/policy/dsl.rb +1 -0
- data/lib/hal_presenter/serializer.rb +9 -3
- metadata +3 -3
- 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: 9f8372f743b3ec9c521a91fcae3b076e895aded53ec5a2c8f1f5aca5dd49cc57
|
4
|
+
data.tar.gz: 0132bffe7bf54366e0c0029d6ad36ab4835157bb122eeb345711554977eabea5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd1ad4fda24796029a64d81339c5271dd55a82079afc0425fab5b5c443af1fe8b12411fe2f13c29ec4fa8cd818b48b991808bceb8d5951846668cc06ebd6180c
|
7
|
+
data.tar.gz: 64f688d70ac9489f3d867e29514cc9c99a4356ae10dafb6417ed37a24a412ee1800f842689a71afc5e8e9c911c301f2d30877cf90b9d0913e6185918b0aefcc4
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
@@ -7,17 +7,31 @@ module HALPresenter
|
|
7
7
|
include Attributes
|
8
8
|
include Links
|
9
9
|
include Curies
|
10
|
+
include Embedded
|
10
11
|
|
11
|
-
attr_reader :name
|
12
|
+
attr_reader :name, :scope
|
12
13
|
|
13
|
-
def initialize(name, &block)
|
14
|
+
def initialize(name, scope, &block)
|
14
15
|
@name = name
|
15
|
-
|
16
|
+
return unless block_given?
|
17
|
+
@scope = scope
|
18
|
+
instance_exec(&block)
|
19
|
+
end
|
20
|
+
|
21
|
+
def method_missing(method, *args, &block)
|
22
|
+
return super unless scope&.respond_to? method
|
23
|
+
define_singleton_method(method) { |*a, &b| scope.public_send method, *a, &b }
|
24
|
+
public_send(method, *args, &block)
|
25
|
+
end
|
26
|
+
|
27
|
+
def respond_to_missing?(method, include_private = false)
|
28
|
+
return true if scope&.respond_to? method
|
29
|
+
super
|
16
30
|
end
|
17
31
|
end
|
18
32
|
|
19
33
|
def collection(of:, &block)
|
20
|
-
@_parameters = CollectionParameters.new(of, &block)
|
34
|
+
@_parameters = CollectionParameters.new(of, self, &block)
|
21
35
|
end
|
22
36
|
|
23
37
|
protected
|
@@ -5,9 +5,9 @@ module HALPresenter
|
|
5
5
|
class Embed < HALPresenter::Property
|
6
6
|
attr_reader :presenter_class
|
7
7
|
|
8
|
-
def initialize(name, value = nil, presenter_class: nil, &block)
|
8
|
+
def initialize(name, value = nil, presenter_class: nil, decorator_class: nil, &block)
|
9
9
|
super(name, value, &block)
|
10
|
-
@presenter_class = presenter_class
|
10
|
+
@presenter_class = presenter_class || decorator_class
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
@@ -54,16 +54,22 @@ module HALPresenter
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def to_collection_hash(resources, options)
|
57
|
+
policy = policy_class&.new(options[:current_user], nil, options)
|
57
58
|
parameters = collection_parameters
|
58
59
|
links = parameters.links
|
59
60
|
curies = parameters.curies
|
60
61
|
{}.tap do |serialized|
|
61
|
-
serialized.merge! _serialize_attributes(parameters.attributes, resources,
|
62
|
-
serialized.merge! _serialize_links(links, curies, resources,
|
62
|
+
serialized.merge! _serialize_attributes(parameters.attributes, resources, policy, options)
|
63
|
+
serialized.merge! _serialize_links(links, curies, resources, policy, options)
|
63
64
|
Pagination.paginate!(serialized, resources) if options[:paginate]
|
64
65
|
|
66
|
+
# Embedded from collection block
|
67
|
+
embedded = _serialize_embedded(parameters.embedded, resources, policy, options)
|
68
|
+
serialized[:_embedded] = embedded[:_embedded] || {}
|
69
|
+
|
70
|
+
# Embedded resources
|
65
71
|
serialized_resources = resources.map { |resource| to_hash(resource, options) }
|
66
|
-
serialized[:_embedded]
|
72
|
+
serialized[:_embedded].merge!({parameters.name => serialized_resources })
|
67
73
|
end
|
68
74
|
end
|
69
75
|
|
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: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sammy Henningsson
|
@@ -31,7 +31,7 @@ cert_chain:
|
|
31
31
|
CNZdF8Vavp6xMQbPHZwqjaeZz2WRXYS7jyYSvCunjwa3OtvXtfbIEGEWE6IM+t9k
|
32
32
|
H1g6Q+B6qk9O6g==
|
33
33
|
-----END CERTIFICATE-----
|
34
|
-
date: 2018-
|
34
|
+
date: 2018-02-05 00:00:00.000000000 Z
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
@@ -198,5 +198,5 @@ rubyforge_project:
|
|
198
198
|
rubygems_version: 2.7.3
|
199
199
|
signing_key:
|
200
200
|
specification_version: 4
|
201
|
-
summary: HAL serializer
|
201
|
+
summary: JSON HAL serializer
|
202
202
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|