record_collection 0.10.2 → 0.10.3
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 +4 -4
- data/CHANGELOG.md +22 -0
- data/lib/record_collection/base.rb +24 -0
- data/lib/record_collection/version.rb +1 -1
- data/spec/base/refine_relation_spec.rb +10 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e447d692e69db528f32f29de1a0532b893b1e686
|
4
|
+
data.tar.gz: 06d7b54baeff7b9787328dcebe3e21b4c0e40d81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de192342a3af0d2b7688b84ce772d073a211aca22577a4c02ff3ba2294c0bd167cd42936407b53ceb87fc04ca632074a688636c1bf4184d3dbfae299138174e1
|
7
|
+
data.tar.gz: 9b91e33a7a272c081dc69a0c0bd6a1bb7f3395c12e47f862db563d3792facdea73d84d6307ec2d4b1b97edf1e7cba4f31ac88587722a242159842d66dd042373
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,28 @@
|
|
1
1
|
CHANGELOG
|
2
2
|
=========
|
3
3
|
|
4
|
+
2015-12-26 - v0.10.3
|
5
|
+
--------------------
|
6
|
+
### Added
|
7
|
+
#### Add includes option for initializing a collection
|
8
|
+
```
|
9
|
+
employees = Employee::Collection.includes(:project).where(state: 'active')
|
10
|
+
employee.map(&:project) #=> one query
|
11
|
+
```
|
12
|
+
|
13
|
+
####
|
14
|
+
Add `#refine_relation` option to refine the collection by means of a
|
15
|
+
scope or include
|
16
|
+
```
|
17
|
+
class Employee
|
18
|
+
def self.with_project
|
19
|
+
includes(:project)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
employees = Employee::Collection.where(state: 'active')
|
23
|
+
employees.refine_relation{ with_project } #=> collection object with refined ActiveRecord relation object if it is instantiated as such
|
24
|
+
```
|
25
|
+
|
4
26
|
2015-12-26 - v0.10.2
|
5
27
|
--------------------
|
6
28
|
### Added
|
@@ -73,6 +73,11 @@ module RecordCollection
|
|
73
73
|
self.new(record_class.joins(*args))
|
74
74
|
end
|
75
75
|
|
76
|
+
# Create a new collection with the scope set to the result of the query on the record_class
|
77
|
+
def includes(*args)
|
78
|
+
self.new(record_class.includes(*args))
|
79
|
+
end
|
80
|
+
|
76
81
|
def all(*args)
|
77
82
|
self.new(record_class.all(*args))
|
78
83
|
end
|
@@ -188,12 +193,31 @@ module RecordCollection
|
|
188
193
|
self.class.model_name
|
189
194
|
end
|
190
195
|
|
196
|
+
def refine_relation(&blk)
|
197
|
+
return self unless defined?(ActiveRecord::Relation)
|
198
|
+
return self unless @collection.is_a?(ActiveRecord::Relation)
|
199
|
+
@collection = @collection.instance_eval(&blk)
|
200
|
+
self
|
201
|
+
end
|
202
|
+
|
191
203
|
# update existing scope with new one having applied where clause if possible
|
192
204
|
def where(*args)
|
193
205
|
@collection = @collection.where(*args)
|
194
206
|
self
|
195
207
|
end
|
196
208
|
|
209
|
+
# update existing scope with new one having applied joins clause if possible
|
210
|
+
def joins(*args)
|
211
|
+
@collection = @collection.joins(*args)
|
212
|
+
self
|
213
|
+
end
|
214
|
+
|
215
|
+
# update existing scope with new one having applied includes clause if possible
|
216
|
+
def includes(*args)
|
217
|
+
@collection = @collection.includes(*args)
|
218
|
+
self
|
219
|
+
end
|
220
|
+
|
197
221
|
# update existing scope with new one having applied not clause if possible
|
198
222
|
def not(*args)
|
199
223
|
@collection = @collection.not(*args)
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe RecordCollection::Base do
|
4
|
+
describe '#refine_relation' do
|
5
|
+
it "does not blow up when array and not ActiveRecord::Relation is given" do
|
6
|
+
expect{ described_class.new([]).refine_relation }.not_to raise_error
|
7
|
+
described_class.new([]).refine_relation{ }.should be_a described_class
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: record_collection
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin ter Kuile
|
@@ -434,6 +434,7 @@ files:
|
|
434
434
|
- spec/base/behaviour_spec.rb
|
435
435
|
- spec/base/finding_records_spec.rb
|
436
436
|
- spec/base/inheritance_spec.rb
|
437
|
+
- spec/base/refine_relation_spec.rb
|
437
438
|
- spec/base/validations_spec.rb
|
438
439
|
- spec/dummy/README.rdoc
|
439
440
|
- spec/dummy/Rakefile
|
@@ -559,6 +560,7 @@ test_files:
|
|
559
560
|
- spec/base/behaviour_spec.rb
|
560
561
|
- spec/base/finding_records_spec.rb
|
561
562
|
- spec/base/inheritance_spec.rb
|
563
|
+
- spec/base/refine_relation_spec.rb
|
562
564
|
- spec/base/validations_spec.rb
|
563
565
|
- spec/dummy/README.rdoc
|
564
566
|
- spec/dummy/Rakefile
|