associationist 0.0.3 → 0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c13e33e027bf5c4f2179768a057f58ec9b9dbebb
4
- data.tar.gz: 8bbf078f6efa66a7f50ba4472745b8dbfdf8cfa8
3
+ metadata.gz: 27b905930acb0b05cc8b74393d757d4a5e919cc9
4
+ data.tar.gz: 322a91a2c6ab442a459e300a1931500e3d7e0078
5
5
  SHA512:
6
- metadata.gz: 69c81e0b47375b0a1cebd5eac7c294b1f582f04d65f099d99a6c7969d77131b80d2970da2c235cdc96922f57087f7a7d25e6b14530d88e59c0fe481ab85e7a95
7
- data.tar.gz: 6701a7aba3615e53fe18045a5db0aa66e9605369a4b91818e9b890b4f8b5a3107663ecdb8ca80d14d872e0c2389700181c8911676c481247cedaa6cce05e1ced
6
+ metadata.gz: 78a23a841019a1846b7ad0a69255cd957bd71625097e62a189e592011e6d77c7616ffaddbbea5adb118b455594341f85f39cfa665362363ff95eb6c038fa1b6d
7
+ data.tar.gz: 29c50724108473603101ba3c167199decffeaae60fafeb995f376e21ac1d25dd784cd73526407a335a716db9ae132c3e8a5c03c4435878678be6aa7386fecc4e
@@ -1,6 +1,6 @@
1
1
  module Associationist
2
2
  module Associations
3
- class CollectionAssociation < ::ActiveRecord::Associations::CollectionAssociation
3
+ class CollectionAssociation < ::ActiveRecord::Associations::HasManyAssociation
4
4
  def association_scope
5
5
  reflection.config.scope_proc.call(owner)
6
6
  end
@@ -8,8 +8,26 @@ module Associationist
8
8
  end
9
9
 
10
10
  def run preloader
11
- @reflection.config.preloader_proc.call(@owners).map do |record, value|
12
- record.association(@reflection.name).target = value
11
+ case
12
+ when @reflection.config.preloader_proc
13
+ @reflection.config.preloader_proc.call(@owners).each do |record, value|
14
+ record.association(@reflection.name).target = value
15
+ end
16
+ when @reflection.config.loader_proc
17
+ @owners.each do |record|
18
+ record.association(@reflection.name).target = @reflection.config.loader_proc.call(record)
19
+ end
20
+ when @reflection.config.scope_proc
21
+ case @reflection.config.type
22
+ when :singular
23
+ @owners.each do |record|
24
+ record.association(@reflection.name).target = @reflection.config.scope_proc.call(record).first
25
+ end
26
+ when :collection
27
+ @owners.each do |record|
28
+ record.association(@reflection.name).target = @reflection.config.scope_proc.call(record)
29
+ end
30
+ end
13
31
  end
14
32
  end
15
33
  end
@@ -1,3 +1,3 @@
1
1
  module Associationist
2
- VERSION = '0.0.3'
2
+ VERSION = '0.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: associationist
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: '0.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - CicholGricenchos