active_record_inherit_assoc 2.9.0 → 2.10.0
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/lib/active_record_inherit_assoc.rb +10 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3114b730174fd26ee0f56c6e133fb5d93706d80770fa265d3c040eb1c29638ec
|
4
|
+
data.tar.gz: b3e5f39e1255c5f588b7b250920eadea41d50fac9285b19f387958d8367eb4b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 << :
|
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 << :
|
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
|
-
|
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)
|
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
|
-
|
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.
|
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-
|
11
|
+
date: 2020-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|