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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27b905930acb0b05cc8b74393d757d4a5e919cc9
|
4
|
+
data.tar.gz: 322a91a2c6ab442a459e300a1931500e3d7e0078
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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::
|
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
|
-
|
12
|
-
|
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
|