associationist 0.1.2 → 0.1.7

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
- SHA1:
3
- metadata.gz: 5dc42ac69ef4e8beec23a8567406fa076dab9f64
4
- data.tar.gz: de294aa901979338765ddd720b32e65804b83b76
2
+ SHA256:
3
+ metadata.gz: c75eb700e6e6c890aec7cae636c49a57738a00771a12fd09f5dda2d162007e48
4
+ data.tar.gz: 362195a0a4dded2bb3a0d7ebf96ecdedecd03a8e886301e345206da54bce3242
5
5
  SHA512:
6
- metadata.gz: e263253c65967cde5e4b30d2821e8807ca5ecfb12ff0f05721da7dfa746312982fbaf998fc8b2497b801cb9a13632b41996d0163a397f6bb9d57e976d7ac101e
7
- data.tar.gz: 604af5c76a3c90963b003804734f16fbe3f99a64e9f31d0d6e2de4daeee2d51fd56a9a2554bf26120fea00ccf00d016f100b70069238cd0f2bc8c8b8c5c8f798
6
+ metadata.gz: b8688e1747f381abf579877309ca810e3835a10e1abe1dccba27254fa1c78f4bba9fb297e3b801543abb4ce0a8dfa38848b61727a73f37d7e6986306338ce38b
7
+ data.tar.gz: f113f4e66963eeef080acaceed81e533903121119696b1975041b6513436aaaebcb3f9f745fef72ce1cee986bc991396fb77678ab749e17ff474c53f9e81d488
@@ -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?
@@ -27,6 +27,14 @@ module Associationist
27
27
  true
28
28
  end
29
29
  end
30
+
31
+ def self.define_writers(mixin, name)
32
+ mixin.class_eval <<-CODE, __FILE__, __LINE__ + 1
33
+ def #{name}=(value)
34
+ raise "Virtual associations are read-only."
35
+ end
36
+ CODE
37
+ end
30
38
  end
31
39
  end
32
40
  end
@@ -7,7 +7,8 @@ module Associationist
7
7
  @reflection = reflection
8
8
  end
9
9
 
10
- def run preloader
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
- reflection.config.scope_proc.call(owner)
7
- else
8
- raise NotImplementedError
9
- end
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
@@ -18,7 +18,12 @@ module Associationist
18
18
 
19
19
  validate_options(options)
20
20
 
21
- scope = build_scope(scope, extension)
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
- scope = build_scope(scope, extension)
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
+ raise "Virtual associations are read-only."
41
+ end
42
+ CODE
43
+ end
44
+
32
45
  end
33
46
  end
34
47
  end
@@ -1,3 +1,3 @@
1
1
  module Associationist
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.7'
3
3
  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.2
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
- - CicholGricenchos
7
+ - onyxblade
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-31 00:00:00.000000000 Z
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
@@ -104,7 +104,7 @@ files:
104
104
  - lib/associationist/reflection/collection_reflection.rb
105
105
  - lib/associationist/reflection/singular_reflection.rb
106
106
  - lib/associationist/version.rb
107
- homepage: https://github.com/CicholGricenchos/associationist
107
+ homepage: https://github.com/onyxblade/associationist
108
108
  licenses:
109
109
  - MIT
110
110
  metadata: {}
@@ -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
- rubyforge_project:
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: ''