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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b50165093b3e78ef2a8ab8efbf0d96e2b31dbe7e
4
- data.tar.gz: a84150b1592e79cced4c06219ebc5c78e9c88266
3
+ metadata.gz: df1b44b0b9255a29b797c8867e334c15b4ccff07
4
+ data.tar.gz: 998fd258d644d42b7136bab89bfc2d91c205c407
5
5
  SHA512:
6
- metadata.gz: 1dc69e235c25fda1536c09d3c196891c4ae57ff8dce3eaf3a1f69f4785071f34f52704b6ffe2a626fa2e69d2090ab0793f418149d78c5f4e739aa6908aa2aeea
7
- data.tar.gz: ccbe88f549fed65ccafbb003c34cfd53f190b0b4ec6228dcaa91813332e8f5bf420896147322996fd918379c70d458b29548ffbeb2c610ddd4626dc96243969e
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, obj| hash[obj] = owner.send(obj) ; 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.class_eval do
29
- prepend ActiveRecordInheritAssocPrepend
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.0
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-07 00:00:00.000000000 Z
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.2.2
173
+ rubygems_version: 2.4.5
174
174
  signing_key:
175
175
  specification_version: 4
176
176
  summary: Attribute inheritance for AR associations