active_record_inherit_assoc 2.2.0 → 2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/active_record_inherit_assoc.rb +22 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df1b44b0b9255a29b797c8867e334c15b4ccff07
|
4
|
+
data.tar.gz: 998fd258d644d42b7136bab89bfc2d91c205c407
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7cb32c32626162fe0a9d0de90116341d9c1f076d3f184b885a1f62882c0322e05bf40be42f975dc26ac44c4d163acc8117a0c412ebb38a59d54e16faaa9c9e8
|
7
|
+
data.tar.gz: 013ef8fe9087f0f39a811f84aca8a66aead61046c8901d9859aff3057d4ff0c6b314f0ee362cbe6f715a802fc135b4e0831671a2adc1153e2eb796a62505adee
|
@@ -21,14 +21,33 @@ module ActiveRecordInheritAssocPrepend
|
|
21
21
|
|
22
22
|
def attribute_inheritance_hash
|
23
23
|
return nil unless reflection.options[:inherit]
|
24
|
-
Array(reflection.options[:inherit]).inject({}) { |hash,
|
24
|
+
Array(reflection.options[:inherit]).inject({}) { |hash, association| hash[association] = owner.send(association) ; hash }
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
ActiveRecord::Associations::Association.
|
29
|
-
|
28
|
+
ActiveRecord::Associations::Association.send(:prepend, ActiveRecordInheritAssocPrepend)
|
29
|
+
|
30
|
+
module ActiveRecordInheritPreloadAssocPrepend
|
31
|
+
def associated_records_by_owner(*args)
|
32
|
+
super.tap do |result|
|
33
|
+
next unless inherit = reflection.options[:inherit]
|
34
|
+
result.each do |owner, associated_records|
|
35
|
+
filter_associated_records_with_inherit!(owner, associated_records, inherit)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def filter_associated_records_with_inherit!(owner, associated_records, inherit)
|
41
|
+
associated_records.select! do |record|
|
42
|
+
Array(inherit).all? do |association|
|
43
|
+
record.send(association) == owner.send(association)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
30
47
|
end
|
31
48
|
|
49
|
+
ActiveRecord::Associations::Preloader::Association.send(:prepend, ActiveRecordInheritPreloadAssocPrepend)
|
50
|
+
|
32
51
|
class ActiveRecord::Base
|
33
52
|
# Makes the model inherit the specified attribute from a named association.
|
34
53
|
#
|
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.2.
|
4
|
+
version: 2.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Osheroff
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -170,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
170
170
|
version: '0'
|
171
171
|
requirements: []
|
172
172
|
rubyforge_project:
|
173
|
-
rubygems_version: 2.
|
173
|
+
rubygems_version: 2.4.5
|
174
174
|
signing_key:
|
175
175
|
specification_version: 4
|
176
176
|
summary: Attribute inheritance for AR associations
|