activerecord-collections 0.0.3 → 0.0.4
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/collections/collectable.rb +34 -0
- data/lib/active_record/collections/serialization.rb +3 -3
- data/lib/active_record/collections/version.rb +1 -1
- data/lib/activerecord-collections.rb +1 -1
- metadata +2 -2
- data/lib/active_record/collections/model_collection.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94403cc736dd576a2be4ca9e465eb22766bf8890
|
4
|
+
data.tar.gz: 0ebfc8a5da14a0f36fb9a5bfb262725f92ff0bb6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab2f87844ce73790ca91a9c74231f3f4adbbfb1bd958f67b5fe2a0ab36e84fef9c1f23f78583c1b4f5a29f3a9dab152ac0f85a142a847299f6cc95bc3514467e
|
7
|
+
data.tar.gz: f9bf87d4ca6d010c642b77c31383e865438f2b7a0c00d87fb4f8f20f3b81bd8ac2ee405a2c44a96d3e11e410fb720b963828bc02ee6174bd18e0cdbb42277bd7
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module Collections
|
3
|
+
module Collectable
|
4
|
+
module Model
|
5
|
+
def collection(*criteria)
|
6
|
+
ActiveRecord::Collection.new(self, *criteria)
|
7
|
+
end
|
8
|
+
alias_method :collect, :collection
|
9
|
+
end
|
10
|
+
|
11
|
+
module Relation
|
12
|
+
def collection
|
13
|
+
ActiveRecord::Collection.from_hash({
|
14
|
+
klass: klass,
|
15
|
+
select: select_values,
|
16
|
+
distinct: distinct_value,
|
17
|
+
joins: joins_values,
|
18
|
+
references: references_values,
|
19
|
+
includes: includes_values,
|
20
|
+
where: where_values.map { |v| v.is_a?(String) ? v : v.to_sql },
|
21
|
+
order: order_values.map { |v| v.is_a?(String) ? v : v.to_sql },
|
22
|
+
bind: bind_values.map { |b| {name: b.first.name, value: b.last} },
|
23
|
+
limit: limit_value,
|
24
|
+
offset: offset_value
|
25
|
+
})
|
26
|
+
end
|
27
|
+
alias_method :collect, :collection
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
ActiveRecord::Base.send :extend, ActiveRecord::Collections::Collectable::Model
|
34
|
+
ActiveRecord::Relation.send :include, ActiveRecord::Collections::Collectable::Relation
|
@@ -12,7 +12,7 @@ module ActiveRecord
|
|
12
12
|
|
13
13
|
def from_hash(hash)
|
14
14
|
hash.symbolize_keys!
|
15
|
-
collection = new
|
15
|
+
collection = new(hash[:klass])
|
16
16
|
collection.select!(*hash[:select]) unless hash[:select].empty?
|
17
17
|
collection.distinct! if hash[:distinct] == true
|
18
18
|
collection.joins!(*hash[:joins]) unless hash[:joins].empty?
|
@@ -20,8 +20,8 @@ module ActiveRecord
|
|
20
20
|
collection.includes!(*hash[:includes]) unless hash[:includes].empty?
|
21
21
|
collection.where!(*hash[:bind].map { |b| b[:value] }.unshift(hash[:where].join(" AND ").gsub(/\$\d/,'?'))) unless hash[:where].empty?
|
22
22
|
collection.order!(hash[:order]) unless hash[:order].empty?
|
23
|
-
collection.limit!(hash[:limit]) unless hash[:limit].
|
24
|
-
collection.offset!(hash[:offset]) unless hash[:offset].
|
23
|
+
collection.limit!(hash[:limit]) unless hash[:limit].nil?
|
24
|
+
collection.offset!(hash[:offset]) unless hash[:offset].nil?
|
25
25
|
collection
|
26
26
|
end
|
27
27
|
end
|
@@ -4,4 +4,4 @@ require 'active_record/collections/relation'
|
|
4
4
|
require 'active_record/collections/records'
|
5
5
|
require 'active_record/collections/serialization'
|
6
6
|
require 'active_record/collection'
|
7
|
-
require 'active_record/collections/
|
7
|
+
require 'active_record/collections/collectable'
|
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.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Rebec
|
@@ -105,8 +105,8 @@ extra_rdoc_files: []
|
|
105
105
|
files:
|
106
106
|
- lib/active_record/collection.rb
|
107
107
|
- lib/active_record/collections/batching.rb
|
108
|
+
- lib/active_record/collections/collectable.rb
|
108
109
|
- lib/active_record/collections/delegation.rb
|
109
|
-
- lib/active_record/collections/model_collection.rb
|
110
110
|
- lib/active_record/collections/records.rb
|
111
111
|
- lib/active_record/collections/relation.rb
|
112
112
|
- lib/active_record/collections/serialization.rb
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
module Collections
|
3
|
-
module ModelCollection
|
4
|
-
def self.included(base)
|
5
|
-
base.send :extend, ClassMethods
|
6
|
-
end
|
7
|
-
|
8
|
-
module ClassMethods
|
9
|
-
def collection(*criteria)
|
10
|
-
ActiveRecord::Collection.new(self, *criteria)
|
11
|
-
end
|
12
|
-
alias_method :collect, :collection
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
ActiveRecord::Base.send :include, ActiveRecord::Collections::ModelCollection
|