pragma-decorator 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ff5939aba8c33bfd6bce0dfe784392ec89b0905
|
4
|
+
data.tar.gz: 24b7825e2c07df12ef69089d7ee854a1bcbcc408
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf9c5241c0107a425dbe86bd802f46ac25c698b219ace26187aa1b5a744ecf18fbbf230ea090f59799964e1c7c632980e2488f9c779a5bae25880f5f8d45ffb1
|
7
|
+
data.tar.gz: 3e6a9cfbfaca8868c8f2f39a9be3978f2e5319c4f7b2e5ac7357413bc2372d83ca6450e0bf800e98e98fe1ab66b71005784c54fe111ce159e041823f89fbb0be
|
data/.rubocop.yml
CHANGED
@@ -53,7 +53,7 @@ Style/BracesAroundHashParameters:
|
|
53
53
|
EnforcedStyle: context_dependent
|
54
54
|
|
55
55
|
Lint/EndAlignment:
|
56
|
-
|
56
|
+
EnforcedStyleAlignWith: variable
|
57
57
|
AutoCorrect: true
|
58
58
|
|
59
59
|
Style/AndOr:
|
@@ -82,3 +82,6 @@ Metrics/PerceivedComplexity:
|
|
82
82
|
|
83
83
|
Metrics/CyclomaticComplexity:
|
84
84
|
Enabled: false
|
85
|
+
|
86
|
+
Metrics/BlockLength:
|
87
|
+
Enabled: false
|
data/doc/03-associations.md
CHANGED
@@ -86,6 +86,6 @@ Here's a list of options accepted when defining an association:
|
|
86
86
|
Name | Type | Default | Meaning
|
87
87
|
---- | ---- | ------- | -------
|
88
88
|
`expandable` | Boolean | `false` | Whether this association is expandable by consumers. Attempting to expand a non-expandable association will raise a `UnexpandableError`.
|
89
|
-
`decorator` | Class | - | If provided, decorates the expanded object with this decorator. Otherwise, simply calls `#to_hash` on the object to get a representable hash.
|
89
|
+
`decorator` | Class|Proc | - | If provided, decorates the expanded object with this decorator. Otherwise, simply calls `#to_hash` on the object to get a representable hash. If the option is callable, will call it and pass the associated object - a decorator class should be returned, or `nil` to skip decoration.
|
90
90
|
`render_nil` | Boolean | `false` | Whether the property should be rendered at all when it is `nil`.
|
91
91
|
`exec_context` | Symbol | `:decorated` | Whether to call the getter on the decorator (`:decorator`) or the decorated object (`:decorated`).
|
@@ -68,8 +68,10 @@ module Pragma
|
|
68
68
|
}
|
69
69
|
}
|
70
70
|
|
71
|
-
|
72
|
-
|
71
|
+
decorator_klass = compute_decorator
|
72
|
+
|
73
|
+
if decorator_klass
|
74
|
+
decorator_klass.new(associated_object).to_hash(options)
|
73
75
|
else
|
74
76
|
associated_object.as_json(options)
|
75
77
|
end
|
@@ -106,6 +108,14 @@ module Pragma
|
|
106
108
|
end
|
107
109
|
end
|
108
110
|
end
|
111
|
+
|
112
|
+
def compute_decorator
|
113
|
+
if reflection.options[:decorator].respond_to?(:call)
|
114
|
+
reflection.options[:decorator].call(associated_object)
|
115
|
+
else
|
116
|
+
reflection.options[:decorator]
|
117
|
+
end
|
118
|
+
end
|
109
119
|
end
|
110
120
|
end
|
111
121
|
end
|
@@ -23,7 +23,8 @@ module Pragma
|
|
23
23
|
# @param options [Hash] additional options
|
24
24
|
#
|
25
25
|
# @option options [Boolean] :expandable (`false`) whether the association is expandable
|
26
|
-
# @option options [Class] :decorator the decorator to use for the associated object
|
26
|
+
# @option options [Class|Proc] :decorator the decorator to use for the associated object
|
27
|
+
# or a callable that will return the decorator class (or +nil+ to skip decoration)
|
27
28
|
# @option options [Boolean] :render_nil (`true`) whether to render a +nil+ association
|
28
29
|
# @option options [Symbol] :exec_context (`decorated`) whether to call the getter on the
|
29
30
|
# decorator (+decorator+) or the decorated object (+decorated+)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pragma-decorator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alessandro Desantis
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: roar
|