associationist 0.1.1 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/associationist/associations/collection_association.rb +5 -1
- data/lib/associationist/associations/preloader/singular_association.rb +7 -1
- data/lib/associationist/associations/singular_association.rb +6 -6
- data/lib/associationist/builder/collection_association.rb +6 -1
- data/lib/associationist/builder/singular_association.rb +14 -1
- data/lib/associationist/reflection/collection_reflection.rb +4 -0
- data/lib/associationist/reflection/singular_reflection.rb +4 -0
- data/lib/associationist/version.rb +1 -1
- metadata +5 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 71ae82541e7c023fb388765d041d9f7e9cf3f13084a4299b7f6c2c954197cbf2
|
4
|
+
data.tar.gz: f49611ceb83887ed9fb24a41611259c3087f715fe612485f9240751613f0ef6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58b53ffc2067262d0f20682ac3eb26bd0f7cf1d23d3aeb7de1f490b6c8540d0923b0616ded48271f198aa46263a90d2f2dbdd8807cc29885e3a10108628e465e
|
7
|
+
data.tar.gz: a98b9f10263294b01ea57430fff3004da4ceb26a7395a3ee073071c124235cff37350ba98d0bc034599302d735edd302d5d29877aaff40f7e9420606f9da4702
|
@@ -2,7 +2,7 @@ module Associationist
|
|
2
2
|
module Associations
|
3
3
|
class CollectionAssociation < ::ActiveRecord::Associations::HasManyAssociation
|
4
4
|
def association_scope
|
5
|
-
reflection.config.scope_proc.call(owner)
|
5
|
+
@_association_scope ||= reflection.config.scope_proc.call(owner)
|
6
6
|
end
|
7
7
|
|
8
8
|
def find_target?
|
@@ -13,6 +13,10 @@ module Associationist
|
|
13
13
|
false
|
14
14
|
end
|
15
15
|
|
16
|
+
def klass
|
17
|
+
association_scope.klass
|
18
|
+
end
|
19
|
+
|
16
20
|
case
|
17
21
|
when ActiveRecord.version < Gem::Version.new('5.2.0')
|
18
22
|
def skip_statement_cache?
|
@@ -7,7 +7,8 @@ module Associationist
|
|
7
7
|
@reflection = reflection
|
8
8
|
end
|
9
9
|
|
10
|
-
|
10
|
+
# handle >= 6.0
|
11
|
+
def run preloader = nil
|
11
12
|
case
|
12
13
|
when @reflection.config.preloader_proc
|
13
14
|
@reflection.config.preloader_proc.call(@owners).each do |record, value|
|
@@ -29,6 +30,11 @@ module Associationist
|
|
29
30
|
end
|
30
31
|
end
|
31
32
|
end
|
33
|
+
self
|
34
|
+
end
|
35
|
+
|
36
|
+
def preloaded_records
|
37
|
+
@owners.flat_map { |owner| owner.association(@reflection.name).target }
|
32
38
|
end
|
33
39
|
end
|
34
40
|
|
@@ -2,11 +2,11 @@ module Associationist
|
|
2
2
|
module Associations
|
3
3
|
class SingularAssociation < ::ActiveRecord::Associations::SingularAssociation
|
4
4
|
def association_scope
|
5
|
-
if reflection.config.scope_proc
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
@_association_scope ||= if reflection.config.scope_proc
|
6
|
+
reflection.config.scope_proc.call(owner)
|
7
|
+
else
|
8
|
+
raise NotImplementedError
|
9
|
+
end
|
10
10
|
end
|
11
11
|
|
12
12
|
def find_target
|
@@ -23,7 +23,7 @@ module Associationist
|
|
23
23
|
|
24
24
|
def klass
|
25
25
|
if reflection.config.scope_proc
|
26
|
-
|
26
|
+
association_scope.klass
|
27
27
|
else
|
28
28
|
Object
|
29
29
|
end
|
@@ -18,7 +18,12 @@ module Associationist
|
|
18
18
|
|
19
19
|
validate_options(options)
|
20
20
|
|
21
|
-
|
21
|
+
case
|
22
|
+
when ActiveRecord.version >= Gem::Version.new('6.0.0')
|
23
|
+
scope = build_scope(scope)
|
24
|
+
else
|
25
|
+
scope = build_scope(scope, extension)
|
26
|
+
end
|
22
27
|
Reflection::CollectionReflection.new(name, scope, options, model)
|
23
28
|
end
|
24
29
|
end
|
@@ -25,10 +25,23 @@ module Associationist
|
|
25
25
|
raise ArgumentError, "association names must be a Symbol" unless name.kind_of?(Symbol)
|
26
26
|
|
27
27
|
validate_options(options)
|
28
|
-
|
28
|
+
case
|
29
|
+
when ActiveRecord.version >= Gem::Version.new('6.0.0')
|
30
|
+
scope = build_scope(scope)
|
31
|
+
else
|
32
|
+
scope = build_scope(scope, extension)
|
33
|
+
end
|
29
34
|
Reflection::SingularReflection.new(name, scope, options, model)
|
30
35
|
end
|
31
36
|
|
37
|
+
def self.define_writers(mixin, name)
|
38
|
+
mixin.class_eval <<-CODE, __FILE__, __LINE__ + 1
|
39
|
+
def #{name}=(value)
|
40
|
+
association(:#{name}).target = value
|
41
|
+
end
|
42
|
+
CODE
|
43
|
+
end
|
44
|
+
|
32
45
|
end
|
33
46
|
end
|
34
47
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: associationist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- CicholGricenchos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: '5.0'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '6'
|
22
|
+
version: '6.1'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: '5.0'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '6'
|
32
|
+
version: '6.1'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: pry
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -123,8 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
requirements: []
|
126
|
-
|
127
|
-
rubygems_version: 2.5.2.3
|
126
|
+
rubygems_version: 3.1.2
|
128
127
|
signing_key:
|
129
128
|
specification_version: 4
|
130
129
|
summary: ''
|