activerecord-collections 0.0.22 → 0.0.23

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: 1c788fe177f07965d7e9fb37df4da779206bd523
4
- data.tar.gz: d37a31f2133132c15a808d1153cd4a312d73501b
3
+ metadata.gz: 192790cbc51085d35ee324b7c2e61936c56285ed
4
+ data.tar.gz: 500efab14683ba051367ea4bcfa72757e8ba4761
5
5
  SHA512:
6
- metadata.gz: 0a991e986d1738e97a4ff0dc74bd8dfde0a91161f2cd490931456b43b088f08dcb7f5f4c51fdd3cc9b0f22d8762beda65b09c8573d09b002e07f6aff14025d6f
7
- data.tar.gz: 1f5dd876dff62b2ac00166134854162cadde85d05dab14a3634d9b18b765a19f88a2b05ba195055462d0b8819f5bff69d210010fa64d139ec81d946dcc5a29ab
6
+ metadata.gz: 8cc2ca473a2f4d6ccee65824c69940ace08445dfdb4ff36b174f3fbbd591f153d5d3eebe72ec6bf3cb532aa51fcaac2522034342b313d00ea1a5c30d6a615076
7
+ data.tar.gz: 1f71fdfa21ecc5ab76419307eb2a23301d26cef231fbe08618c5d29e36f8bb09035eb27877b8b8ab637b120f7142d7e1611814c3cd5bfe99a6fdf32c64009b06
@@ -8,35 +8,32 @@ module ActiveRecord
8
8
  include ActiveRecord::Collections::Pagination
9
9
  attr_reader :relation, :options
10
10
 
11
- @@lock = Mutex.new
11
+ COLLECTABLES = {}
12
+ COLLECTIONS = []
12
13
 
13
14
  class << self
14
15
  attr_reader :collections
15
16
  def inherited(subclass)
16
- @@lock.synchronize do
17
- (@collections ||= []) << subclass
18
- end
17
+ ActiveRecord::Collection::COLLECTIONS << subclass
19
18
  end
20
19
 
21
20
  def collectable(klass=nil)
22
- @@lock.synchronize do
23
- unless klass.nil?
24
- raise ArgumentError, "The collection model must inherit from ActiveRecord::Base" unless klass.ancestors.include?(ActiveRecord::Base)
25
- @collectable = klass
26
- end
21
+ unless klass.nil?
22
+ raise ArgumentError, "The collection model must inherit from ActiveRecord::Base" unless klass.ancestors.include?(ActiveRecord::Base)
23
+ ActiveRecord::Collection::COLLECTABLES[name] ||= klass
24
+ end
27
25
 
28
- if @collectable.nil?
29
- begin
30
- klass = self.name.demodulize.singularize.constantize
31
- @collectable = klass if !klass.nil? && klass.ancestors.include?(ActiveRecord::Base)
32
- rescue
33
- # singularized class doesn't exist
34
- end
26
+ if ActiveRecord::Collection::COLLECTABLES[name].nil?
27
+ begin
28
+ klass = self.name.demodulize.singularize.constantize
29
+ ActiveRecord::Collection::COLLECTABLES[name] = klass if !klass.nil? && klass.ancestors.include?(ActiveRecord::Base)
30
+ rescue
31
+ # singularized class doesn't exist
35
32
  end
36
-
37
- raise "Unable to determine a model to use for your collection, please set one with the `collectable` class method" if @collectable.nil? # TODO implement real exceptions
38
- @collectable
39
33
  end
34
+
35
+ raise "Unable to determine a model to use for your collection, please set one with the `collectable` class method" if ActiveRecord::Collection::COLLECTABLES[name].nil? # TODO implement real exceptions
36
+ ActiveRecord::Collection::COLLECTABLES[name]
40
37
  end
41
38
  alias_method :model, :collectable
42
39
  end
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module Collections
3
- VERSION = '0.0.22'
3
+ VERSION = '0.0.23'
4
4
  end
5
5
  end
@@ -15,8 +15,8 @@ RSpec.describe ActiveRecord::Collection do
15
15
 
16
16
  context 'batching' do
17
17
  describe 'default_batch_size' do
18
- it 'should default to 2000' do
19
- expect(ActiveRecord::Collection.default_batch_size).to eql(2000)
18
+ it 'should default to 500' do
19
+ expect(ActiveRecord::Collection.default_batch_size).to eql(500)
20
20
  end
21
21
 
22
22
  it 'should be overridable by extending classes' do
@@ -25,8 +25,8 @@ RSpec.describe ActiveRecord::Collection do
25
25
  end
26
26
 
27
27
  describe 'batching_threshold' do
28
- it 'should default to 10000' do
29
- expect(ActiveRecord::Collection.batching_threshold).to eql(10000)
28
+ it 'should default to 0' do
29
+ expect(ActiveRecord::Collection.batching_threshold).to eql(0)
30
30
  end
31
31
 
32
32
  it 'should be overridable by extending classes' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-collections
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.22
4
+ version: 0.0.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Rebec