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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 710664013c6c921b9bdfe46c1598143edd489eddcdfc1519f13fb2625462640a
4
- data.tar.gz: 245c76d099c43ffa562ed68bbc387deb49d7fd96814ed294eee1eccbf1b3adad
3
+ metadata.gz: bb1ad9391f72b911e88c22cd1a4e499ce0e66a3c2adddd538fe4efd8a644823d
4
+ data.tar.gz: 1476196c825f6096d90d60844145f92eb6efbeca56edf786805f90fea7c61609
5
5
  SHA512:
6
- metadata.gz: 471441ab9dab08080f516f2a8427938f739154b91f24dd0378f48634f9b4bf444e9103af4c6d49905002d847d9b03a2dab1f0f87edafa7661ad2163f00e12272
7
- data.tar.gz: 3273523f2ecc5997e7cc0ea04eb8bfc7e88b75723293cd1268b7cf21fd6c07ff45daf969402c0245ddde8eb33753fc25546ca851163f946bd233fddbdbb63c1d
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, _args|
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)
@@ -2,5 +2,5 @@
2
2
 
3
3
  module ApiBlocks
4
4
  # Current version of ApiBlocks
5
- VERSION = "0.5.0"
5
+ VERSION = "0.5.1"
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api-blocks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul d'Hubert