activerecord-collections 0.0.20 → 0.0.21
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 +6 -5
- 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: 2d8c2bbbd91158545724fa1361d374e189c81411
|
4
|
+
data.tar.gz: d9a9667c551a532fe1112eaf48bceb7e787b0dcd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ccfc65a4b4b05ab59d90579937cd461f71edd783da29c5562ae340dad2d0c53089ee355f8fbee68409dafd728bf91b8d0e960c6da8be7253b35fceffc49d7161
|
7
|
+
data.tar.gz: 121f1d0935db26f71bafc0994d22f632d066e421fa50aae716d30633f7db02f053ebf9e1656e5f1dbe135b3a4aedc85d311d3e4ba5079ef7e1eb00a1a0d2dda3
|
@@ -9,6 +9,7 @@ module ActiveRecord
|
|
9
9
|
attr_reader :relation, :options
|
10
10
|
|
11
11
|
class << self
|
12
|
+
attr_accessor :kollektable
|
12
13
|
attr_reader :collections
|
13
14
|
def inherited(subclass)
|
14
15
|
(@collections ||= []) << subclass
|
@@ -17,20 +18,20 @@ module ActiveRecord
|
|
17
18
|
def collectable(klass=nil)
|
18
19
|
unless klass.nil?
|
19
20
|
raise ArgumentError, "The collection model must inherit from ActiveRecord::Base" unless klass.ancestors.include?(ActiveRecord::Base)
|
20
|
-
|
21
|
+
self.kollektable = klass
|
21
22
|
end
|
22
23
|
|
23
|
-
if
|
24
|
+
if self.kollektable.nil?
|
24
25
|
begin
|
25
26
|
klass = self.name.demodulize.singularize.constantize
|
26
|
-
|
27
|
+
self.kollektable = klass if !klass.nil? && klass.ancestors.include?(ActiveRecord::Base)
|
27
28
|
rescue
|
28
29
|
# singularized class doesn't exist
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
32
|
-
raise "Unable to determine a model to use for your collection, please set one with the `collectable` class method" if
|
33
|
-
|
33
|
+
raise "Unable to determine a model to use for your collection, please set one with the `collectable` class method" if self.kollektable.nil? # TODO implement real exceptions
|
34
|
+
self.kollektable
|
34
35
|
end
|
35
36
|
alias_method :model, :collectable
|
36
37
|
end
|