alba 3.7.1 → 3.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/lib/alba/association.rb +6 -4
- data/lib/alba/resource.rb +6 -2
- data/lib/alba/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c80fd2a93a15e978c608d4eb9fbe3abaab0f724674d84a3a177134df4664aa3e
|
4
|
+
data.tar.gz: 56b10e5d327f0dbffb3c9d1e82da6a97d318161e22e975c605784e03e184648f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f53bf99dd9170696fc1b5860661b76cb6b2a3ca3803a6ddcced7e4c34ff38fe3d88fd3c6ac7f7b4cd2f6524d53fc6195039d6d6209bfcef770aabfe59d13ea0
|
7
|
+
data.tar.gz: fb028b2759d7892711baca807889a14d8bb11084d3d9fec2f3b6efd6e0cd199ee42f7ceb814e805fcf3ae9a4dccacedb3c6f810b951b500aaff24eb13bff5bbc
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [3.7.3] 2025-06-28
|
10
|
+
|
11
|
+
### Fixed
|
12
|
+
|
13
|
+
- Enable to apply traits for associations [Issue #444](https://github.com/okuramasafumi/alba/issues/444)
|
14
|
+
- Thank you for reporting, @rainerborene
|
15
|
+
|
16
|
+
## [3.7.2] 2025-06-08
|
17
|
+
|
18
|
+
### Fixed
|
19
|
+
|
20
|
+
- apply transform_keys directive for traits [#438](https://github.com/okuramasafumi/alba/pull/436)
|
21
|
+
- Thank you, @elShiaLabeouf
|
22
|
+
|
9
23
|
## [3.7.1] 2025-05-27
|
10
24
|
|
11
25
|
### Fixed
|
data/lib/alba/association.rb
CHANGED
@@ -16,15 +16,17 @@ module Alba
|
|
16
16
|
# @param condition [Proc, nil] a proc filtering data
|
17
17
|
# @param resource [Class<Alba::Resource>, Proc, String, Symbol, nil]
|
18
18
|
# a resource class for the association, a proc returning a resource class or a name of the resource
|
19
|
+
# @param with_traits [Symbol, Array<Symbol>, nil] specified traits
|
19
20
|
# @param params [Hash] params override for the association
|
20
21
|
# @param nesting [String] a namespace where source class is inferred with
|
21
22
|
# @param key_transformation [Symbol] key transformation type
|
22
23
|
# @param helper [Module] helper module to include
|
23
24
|
# @param block [Block] used to define resource when resource arg is absent
|
24
|
-
def initialize(name:, condition: nil, resource: nil, params: {}, nesting: nil, key_transformation: :none, helper: nil, &block)
|
25
|
+
def initialize(name:, condition: nil, resource: nil, with_traits: nil, params: {}, nesting: nil, key_transformation: :none, helper: nil, &block)
|
25
26
|
@name = name
|
26
27
|
@condition = condition
|
27
28
|
@resource = resource
|
29
|
+
@with_traits = with_traits
|
28
30
|
@params = params
|
29
31
|
return if @resource
|
30
32
|
|
@@ -53,7 +55,7 @@ module Alba
|
|
53
55
|
if @resource.is_a?(Proc)
|
54
56
|
return to_h_with_each_resource(object, within, params) if object.is_a?(Enumerable)
|
55
57
|
|
56
|
-
@resource.call(object).new(object, within: within, params: params).to_h
|
58
|
+
@resource.call(object).new(object, within: within, params: params, with_traits: @with_traits).to_h
|
57
59
|
else
|
58
60
|
to_h_with_constantize_resource(object, within, params)
|
59
61
|
end
|
@@ -100,13 +102,13 @@ module Alba
|
|
100
102
|
|
101
103
|
def to_h_with_each_resource(object, within, params)
|
102
104
|
object.map do |item|
|
103
|
-
@resource.call(item).new(item, within: within, params: params).to_h
|
105
|
+
@resource.call(item).new(item, within: within, params: params, with_traits: @with_traits).to_h
|
104
106
|
end
|
105
107
|
end
|
106
108
|
|
107
109
|
def to_h_with_constantize_resource(object, within, params)
|
108
110
|
@resource = constantize(@resource)
|
109
|
-
@resource.new(object, params: params, within: within).to_h
|
111
|
+
@resource.new(object, params: params, within: within, with_traits: @with_traits).to_h
|
110
112
|
end
|
111
113
|
end
|
112
114
|
end
|
data/lib/alba/resource.rb
CHANGED
@@ -121,6 +121,7 @@ module Alba
|
|
121
121
|
|
122
122
|
resource_class = Alba.resource_class
|
123
123
|
resource_class.class_eval(&body)
|
124
|
+
resource_class.transform_keys(@_transform_type) unless @_transform_type == :none
|
124
125
|
h.merge!(resource_class.new(obj, params: params, within: @within, select: method(:select)).serializable_hash)
|
125
126
|
end
|
126
127
|
h
|
@@ -432,17 +433,20 @@ module Alba
|
|
432
433
|
# @param resource [Class<Alba::Resource>, String, Proc, nil] representing resource for this association
|
433
434
|
# @param serializer [Class<Alba::Resource>, String, Proc, nil] alias for `resource`
|
434
435
|
# @param key [String, Symbol, nil] used as key when given
|
436
|
+
# @param with_traits [Symbol, Array<Symbol>, nil] specified traits
|
435
437
|
# @param params [Hash] params override for the association
|
436
438
|
# @param options [Hash<Symbol, Proc>]
|
437
439
|
# @option options [Proc] if a condition to decide if this association should be serialized
|
438
440
|
# @param block [Block]
|
439
441
|
# @return [void]
|
440
442
|
# @see Alba::Association#initialize
|
441
|
-
def association(name, condition = nil, resource: nil, serializer: nil, key: nil, params: {}, **options, &block)
|
443
|
+
def association(name, condition = nil, resource: nil, serializer: nil, key: nil, with_traits: nil, params: {}, **options, &block)
|
442
444
|
resource ||= serializer
|
443
445
|
transformation = @_key_transformation_cascade ? @_transform_type : :none
|
444
446
|
assoc = Association.new(
|
445
|
-
name: name, condition: condition, resource: resource,
|
447
|
+
name: name, condition: condition, resource: resource, with_traits: with_traits,
|
448
|
+
params: params, nesting: nesting, key_transformation: transformation, helper: @_helper,
|
449
|
+
&block
|
446
450
|
)
|
447
451
|
@_attributes[key&.to_sym || name.to_sym] = options[:if] ? ConditionalAttribute.new(body: assoc, condition: options[:if]) : assoc
|
448
452
|
end
|
data/lib/alba/version.rb
CHANGED