active_record_inherit_assoc 2.9.0 → 2.10.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
  SHA256:
3
- metadata.gz: b55c3f0e3b88e52836c8412b5f90299f6bfb5cd3850338328b58e3409afdeefd
4
- data.tar.gz: 743abb357de27dd7954bbbabc1a72ef95ac9928b4762f8031ba55082bb7fed2d
3
+ metadata.gz: 3114b730174fd26ee0f56c6e133fb5d93706d80770fa265d3c040eb1c29638ec
4
+ data.tar.gz: b3e5f39e1255c5f588b7b250920eadea41d50fac9285b19f387958d8367eb4b9
5
5
  SHA512:
6
- metadata.gz: e911e8243061ca030b4293150cd433c1963f72154b849754d2460f02fa85e5b885a691ad3fe7df442de3cb5539fb70b016f100a7bbf0f578a51d9d3d38d42d26
7
- data.tar.gz: 0ad8b533b645a0f71bc7e9978afb571ccdaad7fe889f6d1015b411f457268b62b86cab07d17acaa02cce904d332603606bb4cdb27bd2c521123773e7c4c9df6a
6
+ metadata.gz: 3fae511b4f18e0908e2c155a841896f76b2bd10d30a699c4d104233ad92d1666af3e51d93429e6ec430ec02a1bdc1d90454373b391893f7734536186e364ff39
7
+ data.tar.gz: 1d270c6bc45fdbbf784ac4c7e465a303a06f2f4248f960f68b788fe85516c1848ddc7a4cdbe92ee5b85378f3b2434b8a5270832f9226df397e06314a6a7aeab7
@@ -3,7 +3,7 @@ require 'active_record'
3
3
  case ActiveRecord::VERSION::MAJOR
4
4
  when 4
5
5
  ActiveRecord::Associations::Builder::Association.valid_options << :inherit
6
- ActiveRecord::Associations::Builder::Association.valid_options << :inherit_if
6
+ ActiveRecord::Associations::Builder::Association.valid_options << :inherit_allowed_list
7
7
  when 5
8
8
  # We can't add options into `valid_options` anymore.
9
9
  # Here are the possible solutions:
@@ -13,7 +13,7 @@ when 5
13
13
  #
14
14
  # I went with the first one out of simplicity.
15
15
  ActiveRecord::Associations::Builder::Association::VALID_OPTIONS << :inherit
16
- ActiveRecord::Associations::Builder::Association::VALID_OPTIONS << :inherit_if
16
+ ActiveRecord::Associations::Builder::Association::VALID_OPTIONS << :inherit_allowed_list
17
17
  end
18
18
 
19
19
  module ActiveRecordInheritAssocPrepend
@@ -29,10 +29,11 @@ module ActiveRecordInheritAssocPrepend
29
29
 
30
30
  def attribute_inheritance_hash
31
31
  return nil unless reflection.options[:inherit]
32
+ inherit_allowed_list = reflection.options[:inherit_allowed_list]
32
33
 
33
34
  Array(reflection.options[:inherit]).each_with_object({}) do |association, hash|
34
35
  assoc_value = owner.send(association)
35
- next if reflection.options[:inherit_if] && !reflection.options[:inherit_if].call(owner)
36
+ assoc_value = Array(assoc_value).concat(inherit_allowed_list) if inherit_allowed_list
36
37
  hash[association] = assoc_value
37
38
  hash["#{through_reflection.table_name}.#{association}"] = assoc_value if reflection.options.key?(:through)
38
39
  end
@@ -72,7 +73,10 @@ module ActiveRecordInheritPreloadAssocPrepend
72
73
 
73
74
  if inherit = reflection.options[:inherit]
74
75
  Array(inherit).each do |inherit_assoc|
75
- owner_values = owners.map(&inherit_assoc).compact.uniq
76
+ owner_values = owners.map(&inherit_assoc)
77
+ owner_values.compact!
78
+ owner_values.uniq!
79
+ owner_values.concat(reflection.options[:inherit_allowed_list]) if reflection.options[:inherit_allowed_list]
76
80
  prescope = prescope.where(inherit_assoc => owner_values)
77
81
  end
78
82
  end
@@ -83,7 +87,8 @@ module ActiveRecordInheritPreloadAssocPrepend
83
87
  def filter_associated_records_with_inherit!(owner, associated_records, inherit)
84
88
  associated_records.select! do |record|
85
89
  Array(inherit).all? do |association|
86
- record.send(association) == owner.send(association)
90
+ record_value = record.send(association)
91
+ record_value == owner.send(association) || reflection.options[:inherit_allowed_list]&.include?(record_value)
87
92
  end
88
93
  end
89
94
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_inherit_assoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.9.0
4
+ version: 2.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Osheroff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-15 00:00:00.000000000 Z
11
+ date: 2020-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord