active_record_extended 0.5.0.beta3 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +0 -0
- data/.gitignore +1 -0
- data/.rspec +0 -0
- data/.rubocop.yml +0 -0
- data/.ruby-gemset +0 -0
- data/.ruby-version +0 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +4 -0
- data/CODE_OF_CONDUCT.md +0 -0
- data/Gemfile +0 -0
- data/Gemfile.lock +9 -1
- data/LICENSE.txt +0 -0
- data/README.md +110 -70
- data/Rakefile +0 -0
- data/active_record_extended.gemspec +1 -0
- data/gemfiles/activerecord-50.gemfile +0 -0
- data/gemfiles/activerecord-51.gemfile +0 -0
- data/gemfiles/activerecord-52+.gemfile +0 -0
- data/gemfiles/activerecord-52.gemfile +0 -0
- data/lib/active_record_extended/active_record.rb +0 -0
- data/lib/active_record_extended/arel/nodes.rb +0 -33
- data/lib/active_record_extended/arel/predications.rb +0 -0
- data/lib/active_record_extended/arel/visitors/postgresql_decorator.rb +0 -0
- data/lib/active_record_extended/arel.rb +0 -0
- data/lib/active_record_extended/patch/5_0/predicate_builder_decorator.rb +0 -0
- data/lib/active_record_extended/patch/5_1/where_clause.rb +0 -0
- data/lib/active_record_extended/patch/5_2/where_clause.rb +0 -0
- data/lib/active_record_extended/predicate_builder/array_handler_decorator.rb +0 -0
- data/lib/active_record_extended/query_methods/any_of.rb +0 -0
- data/lib/active_record_extended/query_methods/either.rb +0 -0
- data/lib/active_record_extended/query_methods/inet.rb +0 -0
- data/lib/active_record_extended/query_methods/where_chain.rb +0 -0
- data/lib/active_record_extended/version.rb +1 -1
- data/lib/active_record_extended.rb +0 -0
- data/spec/active_record_extended_spec.rb +0 -0
- data/spec/query_methods/any_of_spec.rb +0 -0
- data/spec/query_methods/array_query_spec.rb +0 -0
- data/spec/query_methods/either_spec.rb +12 -4
- data/spec/query_methods/hash_query_spec.rb +0 -0
- data/spec/query_methods/inet_query_spec.rb +0 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/sql_inspections/any_of_sql_spec.rb +0 -0
- data/spec/sql_inspections/arel/array_spec.rb +0 -0
- data/spec/sql_inspections/arel/inet_spec.rb +0 -0
- data/spec/sql_inspections/contains_sql_queries_spec.rb +0 -0
- data/spec/sql_inspections/either_sql_spec.rb +0 -0
- data/spec/support/database_cleaner.rb +0 -0
- data/spec/support/models.rb +0 -0
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9eeb9aca8c378f3cdb7d615c59b9d2c0490f1c208029d8873af2ed44f75685e
|
4
|
+
data.tar.gz: 2964c85f3aef6d185f416965356248b6a4af918e9e30d9bf238e7bd02aab33b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35abb91e76d72d6c49ac746817a5071dbbc1081493f8506e01f16a4caf462664e890ba9dea3e8d69820bcbd2e0461bc556fada21e3a6e6967150596dcaff3cfd
|
7
|
+
data.tar.gz: 4c550088739bda0c8e42ded831a213abdaa86461864d25e9e236b9a2376758bf69a42afbe3e3c084cfda6294075a77a25415ca7907e7ed94503fb8b998b4c8ff
|
data/.codeclimate.yml
CHANGED
File without changes
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
File without changes
|
data/.rubocop.yml
CHANGED
File without changes
|
data/.ruby-gemset
CHANGED
File without changes
|
data/.ruby-version
CHANGED
File without changes
|
data/.travis.yml
CHANGED
@@ -26,9 +26,15 @@ matrix:
|
|
26
26
|
env: DATABASE_URL=postgres://postgres@localhost/active_record_extended_test
|
27
27
|
|
28
28
|
before_script:
|
29
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
30
|
+
- chmod +x ./cc-test-reporter
|
31
|
+
- ./cc-test-reporter before-build
|
29
32
|
- psql -c 'create database active_record_extended_test;' -U postgres
|
30
33
|
- bundle exec rake db:migrate
|
31
34
|
|
35
|
+
after_script:
|
36
|
+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
37
|
+
|
32
38
|
cache:
|
33
39
|
- bundler
|
34
40
|
|
data/CHANGELOG.md
CHANGED
data/CODE_OF_CONDUCT.md
CHANGED
File without changes
|
data/Gemfile
CHANGED
File without changes
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
active_record_extended (0.5.0
|
4
|
+
active_record_extended (0.5.0)
|
5
5
|
activerecord (>= 5.0, < 6.0)
|
6
6
|
ar_outer_joins (~> 0.2)
|
7
7
|
pg (~> 0.18)
|
@@ -29,9 +29,11 @@ GEM
|
|
29
29
|
concurrent-ruby (1.0.5)
|
30
30
|
database_cleaner (1.7.0)
|
31
31
|
diff-lcs (1.3)
|
32
|
+
docile (1.3.0)
|
32
33
|
dotenv (2.4.0)
|
33
34
|
i18n (1.0.1)
|
34
35
|
concurrent-ruby (~> 1.0)
|
36
|
+
json (2.1.0)
|
35
37
|
method_source (0.9.0)
|
36
38
|
minitest (5.11.3)
|
37
39
|
parallel (1.12.1)
|
@@ -68,6 +70,11 @@ GEM
|
|
68
70
|
ruby-progressbar (~> 1.7)
|
69
71
|
unicode-display_width (~> 1.0, >= 1.0.1)
|
70
72
|
ruby-progressbar (1.9.0)
|
73
|
+
simplecov (0.16.1)
|
74
|
+
docile (~> 1.1)
|
75
|
+
json (>= 1.8, < 3)
|
76
|
+
simplecov-html (~> 0.10.0)
|
77
|
+
simplecov-html (0.10.2)
|
71
78
|
thread_safe (0.3.6)
|
72
79
|
tzinfo (1.2.5)
|
73
80
|
thread_safe (~> 0.1)
|
@@ -87,6 +94,7 @@ DEPENDENCIES
|
|
87
94
|
rake (~> 10.0)
|
88
95
|
rspec (~> 3.0)
|
89
96
|
rubocop (~> 0.52)
|
97
|
+
simplecov (~> 0.16)
|
90
98
|
|
91
99
|
BUNDLED WITH
|
92
100
|
1.16.1
|
data/LICENSE.txt
CHANGED
File without changes
|
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
[![Build Status](https://travis-ci.com/GeorgeKaraszi/ActiveRecordExtended.svg?branch=master)](https://travis-ci.com/GeorgeKaraszi/ActiveRecordExtended)
|
2
|
-
|
1
|
+
[![Build Status](https://travis-ci.com/GeorgeKaraszi/ActiveRecordExtended.svg?branch=master)](https://travis-ci.com/GeorgeKaraszi/ActiveRecordExtended)
|
2
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/98ecffc0239417098cbc/maintainability)](https://codeclimate.com/github/GeorgeKaraszi/active_record_extended/maintainability)
|
3
|
+
[![Test Coverage](https://api.codeclimate.com/v1/badges/f22154211bb3a8feb89f/test_coverage)](https://codeclimate.com/github/GeorgeKaraszi/ActiveRecordExtended/test_coverage)
|
3
4
|
## Index
|
4
5
|
- [Description and history](#description-and-history)
|
5
6
|
- [Installation](#installation)
|
@@ -40,11 +41,11 @@ Active Record Extended is intended to be a supporting community that will mainta
|
|
40
41
|
In Postgres the `ANY` expression is used for gather record's that have an Array column type that contain a single matchable value within its array.
|
41
42
|
|
42
43
|
```ruby
|
43
|
-
alice =
|
44
|
-
bob =
|
45
|
-
randy =
|
44
|
+
alice = User.create!(tags: [1])
|
45
|
+
bob = User.create!(tags: [1, 2])
|
46
|
+
randy = User.create!(tags: [3])
|
46
47
|
|
47
|
-
|
48
|
+
User.where.any(tags: 1) #=> [alice, bob]
|
48
49
|
|
49
50
|
```
|
50
51
|
|
@@ -57,11 +58,11 @@ This only accepts a single value. So querying for example multiple tag numbers `
|
|
57
58
|
In Postgres the `ALL` expression is used for gather record's that have an Array column type that contains only a **single** and matchable element.
|
58
59
|
|
59
60
|
```ruby
|
60
|
-
alice =
|
61
|
-
bob =
|
62
|
-
randy =
|
61
|
+
alice = User.create!(tags: [1])
|
62
|
+
bob = User.create!(tags: [1, 2])
|
63
|
+
randy = User.create!(tags: [3])
|
63
64
|
|
64
|
-
|
65
|
+
User.where.all(tags: 1) #=> [alice]
|
65
66
|
|
66
67
|
```
|
67
68
|
|
@@ -78,20 +79,20 @@ That contains all of the provided values.
|
|
78
79
|
|
79
80
|
Array Type:
|
80
81
|
```ruby
|
81
|
-
alice =
|
82
|
-
bob =
|
83
|
-
randy =
|
82
|
+
alice = User.create!(tags: [1, 4])
|
83
|
+
bob = User.create!(tags: [3, 1])
|
84
|
+
randy = User.create!(tags: [4, 1])
|
84
85
|
|
85
|
-
|
86
|
+
User.where.contains(tags: [1, 4]) #=> [alice, randy]
|
86
87
|
```
|
87
88
|
|
88
89
|
HSTORE / JSONB Type:
|
89
90
|
```ruby
|
90
|
-
alice =
|
91
|
-
bob =
|
92
|
-
randy =
|
91
|
+
alice = User.create!(data: { nickname: "ARExtend" })
|
92
|
+
bob = User.create!(data: { nickname: "ARExtended" })
|
93
|
+
randy = User.create!(data: { nickname: "ARExtended" })
|
93
94
|
|
94
|
-
|
95
|
+
User.where.contains(data: { nickname: "ARExtended" }) #=> [bob, randy]
|
95
96
|
```
|
96
97
|
|
97
98
|
#### Overlap
|
@@ -100,13 +101,13 @@ Person.where.contains(data: { nickname: "ARExtended" }) #=> [bob, randy]
|
|
100
101
|
The `overlap/1` method will match an Array column type that contains any of the provided values within its column.
|
101
102
|
|
102
103
|
```ruby
|
103
|
-
alice =
|
104
|
-
bob =
|
105
|
-
randy =
|
104
|
+
alice = User.create!(tags: [1, 4])
|
105
|
+
bob = User.create!(tags: [3, 4])
|
106
|
+
randy = User.create!(tags: [4, 8])
|
106
107
|
|
107
|
-
|
108
|
-
|
109
|
-
|
108
|
+
User.where.overlap(tags: [4]) #=> [alice, bob, randy]
|
109
|
+
User.where.overlap(tags: [1, 8]) #=> [alice, randy]
|
110
|
+
User.where.overlap(tags: [1, 3, 8]) #=> [alice, bob, randy]
|
110
111
|
|
111
112
|
```
|
112
113
|
|
@@ -118,12 +119,12 @@ The `inet_contains` method works by taking a column(inet type) that has a submas
|
|
118
119
|
And tries to find related records that fall within a given IP's range.
|
119
120
|
|
120
121
|
```ruby
|
121
|
-
alice =
|
122
|
-
bob =
|
122
|
+
alice = User.create!(ip: "127.0.0.1/16")
|
123
|
+
bob = User.create!(ip: "192.168.0.1/16")
|
123
124
|
|
124
|
-
|
125
|
-
|
126
|
-
|
125
|
+
User.where.inet_contains(ip: "127.0.0.254") #=> [alice]
|
126
|
+
User.where.inet_contains(ip: "192.168.20.44") #=> [bob]
|
127
|
+
User.where.inet_contains(ip: "192.255.1.1") #=> []
|
127
128
|
```
|
128
129
|
|
129
130
|
##### Inet Contains or Equals
|
@@ -132,12 +133,12 @@ Person.where.inet_contains(ip: "192.255.1.1") #=> []
|
|
132
133
|
The `inet_contains_or_equals` method works much like the [Inet Contains](#inet-contains) method, but will also accept a submask range.
|
133
134
|
|
134
135
|
```ruby
|
135
|
-
alice =
|
136
|
-
bob =
|
136
|
+
alice = User.create!(ip: "127.0.0.1/10")
|
137
|
+
bob = User.create!(ip: "127.0.0.44/24")
|
137
138
|
|
138
|
-
|
139
|
-
|
140
|
-
|
139
|
+
User.where.inet_contains_or_equals(ip: "127.0.0.1/16") #=> [alice]
|
140
|
+
User.where.inet_contains_or_equals(ip: "127.0.0.1/10") #=> [alice]
|
141
|
+
User.where.inet_contains_or_equals(ip: "127.0.0.1/32") #=> [alice, bob]
|
141
142
|
```
|
142
143
|
|
143
144
|
##### Inet Contained Within
|
@@ -146,12 +147,12 @@ Person.where.inet_contains_or_equals(ip: "127.0.0.1/32") #=> [alice, bob]
|
|
146
147
|
For the `inet_contained_within` method, we try to find IP's that fall within a submasking range we provide.
|
147
148
|
|
148
149
|
```ruby
|
149
|
-
alice =
|
150
|
-
bob =
|
151
|
-
randy =
|
150
|
+
alice = User.create!(ip: "127.0.0.1")
|
151
|
+
bob = User.create!(ip: "127.0.0.44")
|
152
|
+
randy = User.create!(ip: "127.0.55.20")
|
152
153
|
|
153
|
-
|
154
|
-
|
154
|
+
User.where.inet_contained_within(ip: "127.0.0.1/24") #=> [alice, bob]
|
155
|
+
User.where.inet_contained_within(ip: "127.0.0.1/16") #=> [alice, bob, randy]
|
155
156
|
```
|
156
157
|
|
157
158
|
##### Inet Contained Within or Equals
|
@@ -160,13 +161,13 @@ Person.where.inet_contained_within(ip: "127.0.0.1/16") #=> [alice, bob, randy]
|
|
160
161
|
The `inet_contained_within_or_equals` method works much like the [Inet Contained Within](#inet-contained-within) method, but will also accept a submask range.
|
161
162
|
|
162
163
|
```ruby
|
163
|
-
alice =
|
164
|
-
bob =
|
165
|
-
randy =
|
164
|
+
alice = User.create!(ip: "127.0.0.1/10")
|
165
|
+
bob = User.create!(ip: "127.0.0.44/32")
|
166
|
+
randy = User.create!(ip: "127.0.99.1")
|
166
167
|
|
167
|
-
|
168
|
-
|
169
|
-
|
168
|
+
User.where.inet_contained_within_or_equals(ip: "127.0.0.44/32") #=> [bob]
|
169
|
+
User.where.inet_contained_within_or_equals(ip: "127.0.0.1/16") #=> [bob, randy]
|
170
|
+
User.where.inet_contained_within_or_equals(ip: "127.0.0.44/8") #=> [alice, bob, randy]
|
170
171
|
```
|
171
172
|
|
172
173
|
##### Inet Contains or Contained Within
|
@@ -176,13 +177,13 @@ The `inet_contains_or_contained_within` method is a combination of [Inet Contain
|
|
176
177
|
It essentially (the database) tries to use both methods to find as many records as possible that match either condition on both sides.
|
177
178
|
|
178
179
|
```ruby
|
179
|
-
alice =
|
180
|
-
bob =
|
181
|
-
randy =
|
180
|
+
alice = User.create!(ip: "127.0.0.1/24")
|
181
|
+
bob = User.create!(ip: "127.0.22.44/8")
|
182
|
+
randy = User.create!(ip: "127.0.99.1")
|
182
183
|
|
183
|
-
|
184
|
-
|
185
|
-
|
184
|
+
User.where.inet_contains_or_is_contained_within(ip: "127.0.255.80") #=> [bob]
|
185
|
+
User.where.inet_contains_or_is_contained_within(ip: "127.0.0.80") #=> [alice, bob]
|
186
|
+
User.where.inet_contains_or_is_contained_within(ip: "127.0.0.80/8") #=> [alice, bob, randy]
|
186
187
|
```
|
187
188
|
|
188
189
|
### Conditional Methods
|
@@ -195,43 +196,82 @@ Person.where.inet_contains_or_is_contained_within(ip: "127.0.0.80/8") #=> [alice
|
|
195
196
|
|
196
197
|
Querying With Attributes:
|
197
198
|
```ruby
|
198
|
-
alice =
|
199
|
-
bob =
|
200
|
-
randy =
|
199
|
+
alice = User.create!(uid: 1)
|
200
|
+
bob = User.create!(uid: 2)
|
201
|
+
randy = User.create!(uid: 3)
|
201
202
|
|
202
|
-
|
203
|
+
User.where.any_of({ uid: 1 }, { uid: 2 }) #=> [alice, bob]
|
203
204
|
```
|
204
205
|
|
205
206
|
Querying With ActiveRecord Objects:
|
206
207
|
```ruby
|
207
|
-
alice =
|
208
|
-
bob =
|
209
|
-
randy =
|
208
|
+
alice = User.create!(uid: 1)
|
209
|
+
bob = User.create!(uid: 2)
|
210
|
+
randy = User.create!(uid: 3)
|
210
211
|
|
211
|
-
uid_one =
|
212
|
-
uid_two =
|
212
|
+
uid_one = User.where(uid: 1)
|
213
|
+
uid_two = User.where(uid: 2)
|
213
214
|
|
214
|
-
|
215
|
+
User.where.any_of(uid_one, uid_two) #=> [alice, bob]
|
215
216
|
```
|
216
217
|
|
217
218
|
Querying with Joined Relationships:
|
218
219
|
```ruby
|
219
|
-
alice =
|
220
|
-
bob =
|
221
|
-
randy =
|
222
|
-
tag_alice = Tag.create!(
|
223
|
-
tag_bob = Tag.create!(
|
224
|
-
tag_randy = Tag.create!(
|
220
|
+
alice = User.create!(uid: 1)
|
221
|
+
bob = User.create!(uid: 2)
|
222
|
+
randy = User.create!(uid: 3)
|
223
|
+
tag_alice = Tag.create!(user_id: alice.id)
|
224
|
+
tag_bob = Tag.create!(user_id: bob.id)
|
225
|
+
tag_randy = Tag.create!(user_id: randy.id)
|
225
226
|
|
226
|
-
bob_tag_query = Tag.where(
|
227
|
-
randy_tag_query = Tag.where(
|
227
|
+
bob_tag_query = Tag.where(users: { id: bob.id }).includes(:user)
|
228
|
+
randy_tag_query = Tag.where(users: { id: randy.id }).joins(:user)
|
228
229
|
|
229
|
-
Tag.joins(:
|
230
|
+
Tag.joins(:user).where.any_of(bob_tag_query, randy_tag_query) #=> [tag_bob, tag_randy] (with users table joined)
|
230
231
|
```
|
231
232
|
|
232
233
|
#### Either Join
|
234
|
+
|
235
|
+
The `#either_join/2` method is a base ActiveRecord querying method that will joins records based on a set of conditionally joinable tables.
|
236
|
+
|
237
|
+
```ruby
|
238
|
+
class User < ActiveRecord::Base
|
239
|
+
has_one :profile_l, class: "ProfileL"
|
240
|
+
has_one :profile_r, class: "ProfileR"
|
241
|
+
|
242
|
+
scope :completed_profile, -> { either_joins(:profile_l, :profile_r) }
|
243
|
+
end
|
244
|
+
|
245
|
+
alice = User.create!
|
246
|
+
bob = User.create!
|
247
|
+
randy = User.create! # Does not have a single completed profile type
|
248
|
+
ProfileL.create!(user_id: alice.id)
|
249
|
+
ProfileR.create!(user_id: bob.id)
|
250
|
+
|
251
|
+
User.completed_profile #=> [alice, bob]
|
252
|
+
# alternatively
|
253
|
+
User.either_joins(:profile_l, :profile_r) #=> [alice, bob]
|
254
|
+
```
|
255
|
+
|
233
256
|
#### Either Order
|
234
257
|
|
258
|
+
The `#either_order/3` method is a base ActiveRecord querying method that will order a set of columns that may or may not exist for each record.
|
259
|
+
This works similar to how [Either Join](#either-join) works. This does not however exclude records that do not have relationships.
|
260
|
+
|
261
|
+
```ruby
|
262
|
+
alice = User.create!
|
263
|
+
bob = User.create!
|
264
|
+
ProfileL.create!(user_id: alice.id, left_turns: 100)
|
265
|
+
ProfileR.create!(user_id: bob.id, right_turns: 50)
|
266
|
+
|
267
|
+
User.either_order(:asc, profile_l: :left_turns, profile_r: :right_turns) #=> [bob, alice]
|
268
|
+
User.either_order(:desc, profile_l: :left_turns, profile_r: :right_turns) #=> [alice, bob]
|
269
|
+
|
270
|
+
randy = User.create!
|
271
|
+
User.either_order(:asc, profile_l: :left_turns, profile_r: :right_turns) #=> [bob, alice, randy]
|
272
|
+
User.either_order(:desc, profile_l: :left_turns, profile_r: :right_turns) #=> [randy, alice, bob]
|
273
|
+
```
|
274
|
+
|
235
275
|
## Installation
|
236
276
|
|
237
277
|
Add this line to your application's Gemfile:
|
data/Rakefile
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -5,64 +5,31 @@ require "arel/nodes/binary"
|
|
5
5
|
module Arel
|
6
6
|
module Nodes
|
7
7
|
class Overlap < Arel::Nodes::Binary
|
8
|
-
def operator
|
9
|
-
:"&&"
|
10
|
-
end
|
11
8
|
end
|
12
9
|
|
13
10
|
class Contains < Arel::Nodes::Binary
|
14
|
-
def operator
|
15
|
-
:>>
|
16
|
-
end
|
17
11
|
end
|
18
12
|
|
19
13
|
class ContainsHStore < Arel::Nodes::Binary
|
20
|
-
def operator
|
21
|
-
:"@>"
|
22
|
-
end
|
23
14
|
end
|
24
15
|
|
25
16
|
class ContainsArray < Arel::Nodes::Binary
|
26
|
-
def operator
|
27
|
-
:"@>"
|
28
|
-
end
|
29
17
|
end
|
30
18
|
|
31
19
|
class ContainedInArray < Arel::Nodes::Binary
|
32
|
-
def operator
|
33
|
-
:"<@"
|
34
|
-
end
|
35
20
|
end
|
36
21
|
|
37
22
|
module Inet
|
38
23
|
class ContainsEquals < Arel::Nodes::Binary
|
39
|
-
def operator
|
40
|
-
:">>="
|
41
|
-
end
|
42
24
|
end
|
43
25
|
|
44
26
|
class ContainedWithin < Arel::Nodes::Binary
|
45
|
-
def operator
|
46
|
-
:<<
|
47
|
-
end
|
48
27
|
end
|
49
28
|
|
50
29
|
class ContainedWithinEquals < Arel::Nodes::Binary
|
51
|
-
def operator
|
52
|
-
:"<<="
|
53
|
-
end
|
54
30
|
end
|
55
31
|
|
56
32
|
class ContainsOrContainedWithin < Arel::Nodes::Binary
|
57
|
-
def operator
|
58
|
-
:"&&"
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
class Node
|
64
|
-
def group_or(right)
|
65
|
-
Arel::Nodes::Or.new self, Arel::Nodes::Grouping.new(right)
|
66
33
|
end
|
67
34
|
end
|
68
35
|
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -28,23 +28,31 @@ RSpec.describe "Active Record Either Methods" do
|
|
28
28
|
describe ".either_order/2" do
|
29
29
|
it "Should not exclude anyone who does not have a relationship" do
|
30
30
|
query = Person.either_order(:asc, profile_l: :likes, profile_r: :dislikes)
|
31
|
-
expect(query).to
|
31
|
+
expect(query.count).to eq(3)
|
32
|
+
expect(query[0]).to eq(two)
|
33
|
+
expect(query[1]).to eq(one)
|
34
|
+
expect(query[2]).to eq(three)
|
32
35
|
end
|
33
36
|
|
34
37
|
it "Should order people based on their likes and dislikes in ascended order" do
|
35
38
|
query = Person.either_order(:asc, profile_l: :likes, profile_r: :dislikes).where(id: [one.id, two.id])
|
36
|
-
expect(query).to
|
39
|
+
expect(query.count).to eq(2)
|
40
|
+
expect(query.first).to eq(two)
|
41
|
+
expect(query.last).to eq(one)
|
37
42
|
end
|
38
43
|
|
39
44
|
it "Should order people based on their likes and dislikes in descending order" do
|
40
45
|
query = Person.either_order(:desc, profile_l: :likes, profile_r: :dislikes).where(id: [one.id, two.id])
|
41
|
-
expect(query).to
|
46
|
+
expect(query.first).to eq(one)
|
47
|
+
expect(query.last).to eq(two)
|
42
48
|
end
|
43
49
|
|
44
50
|
context "Alias .either_order/2" do
|
45
51
|
it "Should order people based on their likes and dislikes in ascended order" do
|
46
52
|
query = Person.either_orders(:asc, profile_l: :likes, profile_r: :dislikes).where(id: [one.id, two.id])
|
47
|
-
expect(query).to
|
53
|
+
expect(query.count).to eq(2)
|
54
|
+
expect(query.first).to eq(two)
|
55
|
+
expect(query.last).to eq(one)
|
48
56
|
end
|
49
57
|
end
|
50
58
|
end
|
File without changes
|
File without changes
|
data/spec/spec_helper.rb
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/spec/support/models.rb
CHANGED
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record_extended
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.0
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- George Protacio-Karaszi
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2018-05-
|
13
|
+
date: 2018-05-31 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
@@ -116,6 +116,20 @@ dependencies:
|
|
116
116
|
- - "~>"
|
117
117
|
- !ruby/object:Gem::Version
|
118
118
|
version: '3.0'
|
119
|
+
- !ruby/object:Gem::Dependency
|
120
|
+
name: simplecov
|
121
|
+
requirement: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - "~>"
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0.16'
|
126
|
+
type: :development
|
127
|
+
prerelease: false
|
128
|
+
version_requirements: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - "~>"
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0.16'
|
119
133
|
description: Adds extended functionality to Activerecord Postgres implementation
|
120
134
|
email:
|
121
135
|
- georgekaraszi@gmail.com
|
@@ -192,9 +206,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
192
206
|
version: '0'
|
193
207
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
194
208
|
requirements:
|
195
|
-
- - "
|
209
|
+
- - ">="
|
196
210
|
- !ruby/object:Gem::Version
|
197
|
-
version:
|
211
|
+
version: '0'
|
198
212
|
requirements: []
|
199
213
|
rubyforge_project:
|
200
214
|
rubygems_version: 2.7.6
|