activerecord-collections 0.0.21 → 0.0.22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/active_record/collection.rb +20 -15
- data/lib/active_record/collections/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c788fe177f07965d7e9fb37df4da779206bd523
|
4
|
+
data.tar.gz: d37a31f2133132c15a808d1153cd4a312d73501b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a991e986d1738e97a4ff0dc74bd8dfde0a91161f2cd490931456b43b088f08dcb7f5f4c51fdd3cc9b0f22d8762beda65b09c8573d09b002e07f6aff14025d6f
|
7
|
+
data.tar.gz: 1f5dd876dff62b2ac00166134854162cadde85d05dab14a3634d9b18b765a19f88a2b05ba195055462d0b8819f5bff69d210010fa64d139ec81d946dcc5a29ab
|
@@ -8,30 +8,35 @@ module ActiveRecord
|
|
8
8
|
include ActiveRecord::Collections::Pagination
|
9
9
|
attr_reader :relation, :options
|
10
10
|
|
11
|
+
@@lock = Mutex.new
|
12
|
+
|
11
13
|
class << self
|
12
|
-
attr_accessor :kollektable
|
13
14
|
attr_reader :collections
|
14
15
|
def inherited(subclass)
|
15
|
-
|
16
|
+
@@lock.synchronize do
|
17
|
+
(@collections ||= []) << subclass
|
18
|
+
end
|
16
19
|
end
|
17
20
|
|
18
21
|
def collectable(klass=nil)
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
23
27
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
30
35
|
end
|
31
|
-
end
|
32
36
|
|
33
|
-
|
34
|
-
|
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
|
+
end
|
35
40
|
end
|
36
41
|
alias_method :model, :collectable
|
37
42
|
end
|