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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 192790cbc51085d35ee324b7c2e61936c56285ed
|
4
|
+
data.tar.gz: 500efab14683ba051367ea4bcfa72757e8ba4761
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
11
|
+
COLLECTABLES = {}
|
12
|
+
COLLECTIONS = []
|
12
13
|
|
13
14
|
class << self
|
14
15
|
attr_reader :collections
|
15
16
|
def inherited(subclass)
|
16
|
-
|
17
|
-
(@collections ||= []) << subclass
|
18
|
-
end
|
17
|
+
ActiveRecord::Collection::COLLECTIONS << subclass
|
19
18
|
end
|
20
19
|
|
21
20
|
def collectable(klass=nil)
|
22
|
-
|
23
|
-
unless klass.
|
24
|
-
|
25
|
-
|
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
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
@@ -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
|
19
|
-
expect(ActiveRecord::Collection.default_batch_size).to eql(
|
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
|
29
|
-
expect(ActiveRecord::Collection.batching_threshold).to eql(
|
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
|