record_collection 0.9.1 → 0.9.2
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/.travis.yml +4 -4
- data/CHANGELOG.md +16 -0
- data/lib/record_collection/base.rb +21 -4
- data/lib/record_collection/version.rb +1 -1
- data/spec/base/finding_records_spec.rb +24 -0
- data/spec/dummy/app/models/employee.rb +1 -0
- data/spec/dummy/app/models/project.rb +1 -0
- data/spec/dummy/db/migrate/20151215123553_add_project_id_to_employees.rb +5 -0
- data/spec/dummy/db/schema.rb +2 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d474fd59cf658f40154411ed1921864f724ef16
|
4
|
+
data.tar.gz: 5a1ab9d2d6215fa356a6a1ab492c8eb46b5ec1ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a823124e2cc13030e85249442d9ba357098e42fe2e6f006b0abf6b1210faf4a3483175cb7cc673a5b36a7f17e42f3c4d9e2790bf3dc936000bc641f4a506e57f
|
7
|
+
data.tar.gz: a5efd9d8bb02240dbd0ed7c14c296a61ef9e5c63d8f70a085b67a33d2d120628e7d1416c2240c8372f3e764cf227284b32c1ce500fba27be70dfaf719eb81975
|
data/.travis.yml
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
3
|
- 2.1.6
|
4
|
-
- 2.2.
|
4
|
+
- 2.2.3
|
5
5
|
env:
|
6
|
-
- RAILS_VERSION=4.1.
|
7
|
-
- RAILS_VERSION=4.2.
|
8
|
-
|
6
|
+
- RAILS_VERSION=4.1.14
|
7
|
+
- RAILS_VERSION=4.2.5
|
8
|
+
- RAILS_VERSION=master
|
9
9
|
addons:
|
10
10
|
code_climate:
|
11
11
|
repo_token: 22819b10ef9110a7fef884ab105239fc16fd0562ac79ae54c2204b5e07343919
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,22 @@
|
|
1
1
|
CHANGELOG
|
2
2
|
=========
|
3
3
|
|
4
|
+
2015-12-15 - v0.9.2
|
5
|
+
-------------------
|
6
|
+
|
7
|
+
### Added
|
8
|
+
#### Allow initialize with multiple chaning scope
|
9
|
+
```
|
10
|
+
Employee::Collection.where(a: 1).where(b: 3)
|
11
|
+
Employee::Collection.where(a: 1).where.not(b: 3)
|
12
|
+
```
|
13
|
+
|
14
|
+
2015-12-09 - v0.9.1
|
15
|
+
-------------------
|
16
|
+
|
17
|
+
### Added
|
18
|
+
* Use string separator argument like: RecordCollection.id\_separator
|
19
|
+
|
4
20
|
2015-11-03 - v0.9.0
|
5
21
|
-------------------
|
6
22
|
|
@@ -65,11 +65,16 @@ module RecordCollection
|
|
65
65
|
|
66
66
|
# Create a new collection with the scope set to the result of the query on the record_class
|
67
67
|
def where(*args)
|
68
|
-
new
|
68
|
+
self.new(record_class.where(*args))
|
69
69
|
end
|
70
70
|
|
71
|
-
|
72
|
-
|
71
|
+
# Create a new collection with the scope set to the result of the query on the record_class
|
72
|
+
def joins(*args)
|
73
|
+
self.new(record_class.joins(*args))
|
74
|
+
end
|
75
|
+
|
76
|
+
def all(*args)
|
77
|
+
self.new(record_class.all(*args))
|
73
78
|
end
|
74
79
|
end
|
75
80
|
|
@@ -144,7 +149,7 @@ module RecordCollection
|
|
144
149
|
# This method returns nil when the values of `attr` in the collection
|
145
150
|
# are mixed. Otherwise the value itself. For boolean attributes the
|
146
151
|
# check is wether the values are truthy or falsy. If the
|
147
|
-
# set_if_nil: true
|
152
|
+
# set_if_nil: true
|
148
153
|
# option is given, a uniform value will be set as the collection value if
|
149
154
|
# it is not already set. This is important since there might be a uniform
|
150
155
|
# value in the collection, but the values of the collection are a result of
|
@@ -173,5 +178,17 @@ module RecordCollection
|
|
173
178
|
def model_name
|
174
179
|
self.class.model_name
|
175
180
|
end
|
181
|
+
|
182
|
+
# update existing scope with new one having applied where clause if possible
|
183
|
+
def where(*args)
|
184
|
+
@collection = @collection.where(*args)
|
185
|
+
self
|
186
|
+
end
|
187
|
+
|
188
|
+
# update existing scope with new one having applied not clause if possible
|
189
|
+
def not(*args)
|
190
|
+
@collection = @collection.not(*args)
|
191
|
+
self
|
192
|
+
end
|
176
193
|
end
|
177
194
|
end
|
@@ -51,4 +51,28 @@ RSpec.describe Employee::Collection do
|
|
51
51
|
described_class.all.collection.should eq [employee]
|
52
52
|
end
|
53
53
|
end
|
54
|
+
|
55
|
+
describe '.joins' do
|
56
|
+
let(:project_1){ Project.create name: 'P1', finished: true }
|
57
|
+
let(:project_2){ Project.create name: 'P2', finished: false }
|
58
|
+
let!(:employee_1){ Employee.create name: 'E1', section: 'ABC', project: project_1 }
|
59
|
+
let!(:employee_2){ Employee.create name: 'E1', section: 'ABC', project: project_2 }
|
60
|
+
it "returns a scope having a joins activated without further arguments" do
|
61
|
+
result = described_class.joins(:project)
|
62
|
+
result.should be_a RecordCollection::Base
|
63
|
+
result.map(&:project).should match_array [project_1, project_2]
|
64
|
+
end
|
65
|
+
|
66
|
+
it "modifies the scope when a .where clause is applied on an existing relation" do
|
67
|
+
result = described_class.joins(:project).where(projects: {finished: true})
|
68
|
+
result.should be_a RecordCollection::Base
|
69
|
+
result.map(&:project).should eq [project_1]
|
70
|
+
end
|
71
|
+
|
72
|
+
it "modifies the scope when a .where.not clause is applied on an existing relation" do
|
73
|
+
result = described_class.joins(:project).where.not(projects: {finished: true})
|
74
|
+
result.should be_a RecordCollection::Base
|
75
|
+
result.map(&:project).should eq [project_2]
|
76
|
+
end
|
77
|
+
end
|
54
78
|
end
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended that you check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(version:
|
14
|
+
ActiveRecord::Schema.define(version: 20151215123553) do
|
15
15
|
|
16
16
|
create_table "employees", force: :cascade do |t|
|
17
17
|
t.string "name"
|
@@ -20,6 +20,7 @@ ActiveRecord::Schema.define(version: 20150721122805) do
|
|
20
20
|
t.datetime "updated_at", null: false
|
21
21
|
t.boolean "vegan", default: true
|
22
22
|
t.boolean "admin", default: false
|
23
|
+
t.integer "project_id"
|
23
24
|
end
|
24
25
|
|
25
26
|
create_table "projects", force: :cascade do |t|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: record_collection
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin ter Kuile
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -474,6 +474,7 @@ files:
|
|
474
474
|
- spec/dummy/db/migrate/20150204103925_add_admin_to_employees.rb
|
475
475
|
- spec/dummy/db/migrate/20150204125014_create_projects.rb
|
476
476
|
- spec/dummy/db/migrate/20150721122805_add_description_to_projects.rb
|
477
|
+
- spec/dummy/db/migrate/20151215123553_add_project_id_to_employees.rb
|
477
478
|
- spec/dummy/db/schema.rb
|
478
479
|
- spec/dummy/lib/assets/.keep
|
479
480
|
- spec/dummy/log/.keep
|
@@ -594,6 +595,7 @@ test_files:
|
|
594
595
|
- spec/dummy/db/migrate/20150204103925_add_admin_to_employees.rb
|
595
596
|
- spec/dummy/db/migrate/20150204125014_create_projects.rb
|
596
597
|
- spec/dummy/db/migrate/20150721122805_add_description_to_projects.rb
|
598
|
+
- spec/dummy/db/migrate/20151215123553_add_project_id_to_employees.rb
|
597
599
|
- spec/dummy/db/schema.rb
|
598
600
|
- spec/dummy/lib/assets/.keep
|
599
601
|
- spec/dummy/log/.keep
|