activerecord-collections 0.0.12 → 0.0.13
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: 04112ca97ff8955d8c031f7f5a2f2a485d542d1e
|
4
|
+
data.tar.gz: 9a7cfa08962b824a6eeba91be93b5aff5a23a37e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af95c3591f0e8829550b4041282b713ef97532ccdfd79ee068467da0b8de6741ffe445792f4109c338fe43108810811db02a3105246bac65754d8e708ceb37fe
|
7
|
+
data.tar.gz: bc5472e5748c8eb9444b5558d756443984dffc3b966b4d03e63e69e499ecb7c9bfb7c7418084dfc53dc1729c5abe8b860e0212f8de7b67729aada847fc938b35
|
@@ -53,7 +53,9 @@ module ActiveRecord
|
|
53
53
|
protected
|
54
54
|
|
55
55
|
def initialize(*criteria)
|
56
|
-
|
56
|
+
criteria.compact!
|
57
|
+
|
58
|
+
if criteria.first.present? && criteria.first.respond_to?(:ancestors) && criteria.first < ActiveRecord::Base
|
57
59
|
@collectable = criteria.slice!(0)
|
58
60
|
end
|
59
61
|
|
@@ -6,6 +6,7 @@ module ActiveRecord
|
|
6
6
|
@collection_class = klass unless klass.nil?
|
7
7
|
@collection_class
|
8
8
|
end
|
9
|
+
alias_method :collector, :collection_class
|
9
10
|
|
10
11
|
def kollektion
|
11
12
|
plural_klass = begin
|
@@ -32,18 +33,18 @@ module ActiveRecord
|
|
32
33
|
def collection
|
33
34
|
# do this with a hash so that we don't cause the relation query to execute
|
34
35
|
kollektion.from_hash({
|
35
|
-
|
36
|
-
select:
|
37
|
-
distinct:
|
38
|
-
joins:
|
39
|
-
references:
|
40
|
-
includes:
|
41
|
-
where:
|
42
|
-
group:
|
43
|
-
order:
|
44
|
-
bind:
|
45
|
-
limit:
|
46
|
-
offset:
|
36
|
+
collectable: klass,
|
37
|
+
select: select_values,
|
38
|
+
distinct: distinct_value,
|
39
|
+
joins: joins_values,
|
40
|
+
references: references_values,
|
41
|
+
includes: includes_values,
|
42
|
+
where: where_values.map { |v| v.is_a?(String) ? v : v.to_sql },
|
43
|
+
group: group_values.map { |v| (v.is_a?(String) || v.is_a?(Symbol)) ? v : v.to_sql },
|
44
|
+
order: order_values.map { |v| (v.is_a?(String) || v.is_a?(Symbol)) ? v : v.to_sql },
|
45
|
+
bind: bind_values.map { |b| {name: b.first.name, value: b.last} },
|
46
|
+
limit: limit_value,
|
47
|
+
offset: offset_value
|
47
48
|
})
|
48
49
|
end
|
49
50
|
alias_method :to_collection, :collection
|
@@ -12,7 +12,10 @@ module ActiveRecord
|
|
12
12
|
|
13
13
|
def from_hash(hash)
|
14
14
|
hash.symbolize_keys! unless hash.is_a?(HashWithIndifferentAccess)
|
15
|
-
|
15
|
+
|
16
|
+
kollektion = kollektion_from_hash(hash)
|
17
|
+
kollektable = kollektable_from_hash(hash)
|
18
|
+
collection = kollektion.new(kollektable)
|
16
19
|
collection.select!(*hash[:select]) unless hash[:select].empty?
|
17
20
|
collection.distinct! if hash[:distinct] == true
|
18
21
|
collection.joins!(*hash[:joins]) unless hash[:joins].empty?
|
@@ -25,6 +28,22 @@ module ActiveRecord
|
|
25
28
|
collection.offset!(hash[:offset]) unless hash[:offset].nil?
|
26
29
|
collection
|
27
30
|
end
|
31
|
+
|
32
|
+
def kollektion_from_hash(hash)
|
33
|
+
kollektion = self
|
34
|
+
kollektion = hash[:collection] if hash.has_key?(:collection)
|
35
|
+
kollektion = kollektion.constantize unless kollektion.is_a?(Class)
|
36
|
+
raise "Invalid collection class: #{kollektion}" unless kollektion <= ActiveRecord::Collection
|
37
|
+
kollektion
|
38
|
+
end
|
39
|
+
|
40
|
+
def kollektable_from_hash(hash)
|
41
|
+
kollektable = nil
|
42
|
+
kollektable = hash[:collectable] if hash.has_key?(:collectable)
|
43
|
+
kollektable = kollektable.constantize unless kollektable.is_a?(Class)
|
44
|
+
raise "Invalid collectable model: #{kollektable}" unless kollektable < ActiveRecord::Base
|
45
|
+
kollektable
|
46
|
+
end
|
28
47
|
end
|
29
48
|
|
30
49
|
def to_sql
|
@@ -33,16 +52,18 @@ module ActiveRecord
|
|
33
52
|
|
34
53
|
def to_hash(include_limit=false)
|
35
54
|
h = {
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
55
|
+
collectable: collectable,
|
56
|
+
select: select_values,
|
57
|
+
distinct: distinct_value,
|
58
|
+
joins: joins_values,
|
59
|
+
references: references_values,
|
60
|
+
includes: includes_values,
|
61
|
+
where: where_values.map { |v| v.is_a?(String) ? v : v.to_sql },
|
62
|
+
group: group_values.map { |v| (v.is_a?(String) || v.is_a?(Symbol)) ? v : v.to_sql },
|
63
|
+
order: order_values.map { |v| (v.is_a?(String) || v.is_a?(Symbol)) ? v : v.to_sql },
|
64
|
+
bind: bind_values.map { |b| {name: b.first.name, value: b.last} }
|
45
65
|
}
|
66
|
+
h[:collection] = self.class if self.class < ActiveRecord::Collection
|
46
67
|
if include_limit || try(:is_batch?)
|
47
68
|
h[:limit] = limit_value
|
48
69
|
h[:offset] = offset_value
|