api-blocks 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/api_blocks/blueprinter/association_extractor.rb +11 -5
- data/lib/api_blocks/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: bb1ad9391f72b911e88c22cd1a4e499ce0e66a3c2adddd538fe4efd8a644823d
|
4
|
+
data.tar.gz: 1476196c825f6096d90d60844145f92eb6efbeca56edf786805f90fea7c61609
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7ecf6130b74a07bf7e0be3d2d0d02122f8a33d04c8391b519706b3b5ed90e850acaa541961e9c97662a3170761cf1f62799e36a656bade77e32508f634f8c18
|
7
|
+
data.tar.gz: af9740a29417e248b15b4804982ce7932ee8f43c05d95baa12e1b1bb9a05c2457c4837c1c23c16a50ff954961b926e54942122597b45a7f14d1e38c27dc18f25
|
@@ -24,29 +24,35 @@ class Blueprinter::AssociationExtractor < Blueprinter::Extractor
|
|
24
24
|
end
|
25
25
|
|
26
26
|
view = options[:view] || :default
|
27
|
+
scope = if options[:block].present?
|
28
|
+
options[:block].call(object, local_options)
|
29
|
+
else
|
30
|
+
{}
|
31
|
+
end
|
27
32
|
|
28
33
|
BatchLoader.for(association_id).batch(
|
29
34
|
default_value: default_value,
|
30
|
-
key: [association_name, association_klass, view, options[:blueprint]],
|
31
|
-
) do |ids, loader,
|
35
|
+
key: [association_name, association_klass, view, options[:blueprint], scope],
|
36
|
+
) do |ids, loader, args|
|
32
37
|
model = association_klass.safe_constantize
|
38
|
+
scope = args[:key].last
|
33
39
|
|
34
40
|
case association
|
35
41
|
when ActiveRecord::Associations::HasManyAssociation
|
36
|
-
model.where(join_key.key => ids).each do |record|
|
42
|
+
model.where(join_key.key => ids).merge(scope).each do |record|
|
37
43
|
loader.call(record.send(join_key.key)) do |memo|
|
38
44
|
memo << render_blueprint(record, local_options, options)
|
39
45
|
end
|
40
46
|
end
|
41
47
|
when ActiveRecord::Associations::HasOneAssociation
|
42
|
-
model.where(join_key.key => ids).each do |record|
|
48
|
+
model.where(join_key.key => ids).merge(scope).each do |record|
|
43
49
|
loader.call(
|
44
50
|
record.send(join_key.key),
|
45
51
|
render_blueprint(record, local_options, options)
|
46
52
|
)
|
47
53
|
end
|
48
54
|
when ActiveRecord::Associations::BelongsToAssociation
|
49
|
-
model.where(join_key.key => ids).each do |record|
|
55
|
+
model.where(join_key.key => ids).merge(scope).each do |record|
|
50
56
|
loader.call(
|
51
57
|
record.id,
|
52
58
|
render_blueprint(record, local_options, options)
|
data/lib/api_blocks/version.rb
CHANGED