rails_or 1.1.5 → 1.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +37 -3
- data/lib/rails_or.rb +4 -0
- data/lib/rails_or/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f9c88ae5f5c4ed9ac8fb2cfc64dbe22be904da8
|
4
|
+
data.tar.gz: 639ff10eb8da02ab73d0a5701b75c2fa5a438b08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22dabe94aee61e0c55067c1249b1e247069d0d63ea3273360148408ba6614fcf30cc7ea64ca38edca4d22e092461884a6fa3fe3b0f656543859b035a5a8cf75a
|
7
|
+
data.tar.gz: a4ad1799eb864d973f8fa0bdc8581e2e71792104a53c155c5729fc6d66277dedb4355064ba63260076ce8887a3509cc17468ec46b690e7b89d457fd7dcb0067a
|
data/README.md
CHANGED
@@ -63,9 +63,9 @@ Person.where(name: 'Pearl').or('age = ?', 24)
|
|
63
63
|
Person.where(name: 'Pearl').or('age = 24')
|
64
64
|
```
|
65
65
|
|
66
|
-
|
66
|
+
## Other convenient methods
|
67
67
|
|
68
|
-
|
68
|
+
### or_not
|
69
69
|
(Only supports in Rails 4+)
|
70
70
|
```rb
|
71
71
|
Company.where.not(logo_image1: nil)
|
@@ -74,7 +74,7 @@ Company.where.not(logo_image1: nil)
|
|
74
74
|
.or_not(logo_image4: nil)
|
75
75
|
```
|
76
76
|
|
77
|
-
|
77
|
+
### or_having
|
78
78
|
|
79
79
|
```rb
|
80
80
|
Order.group('user_id')
|
@@ -82,6 +82,40 @@ Order.group('user_id')
|
|
82
82
|
.or_having('COUNT(*) > 10')
|
83
83
|
```
|
84
84
|
|
85
|
+
## Examples
|
86
|
+
|
87
|
+
Let `A = {id: 1}`, `B = {account: 'a'}`, and `C = {email: 'b'}`
|
88
|
+
|
89
|
+
### A && (B || C)
|
90
|
+
```rb
|
91
|
+
u = User.where(A)
|
92
|
+
u.where(B).or(u.where(C))
|
93
|
+
# =>
|
94
|
+
# SELECT `users`.* FROM `users`
|
95
|
+
# WHERE `users`.`id` = 1 AND (`users`.`account` = 'a' OR `users`.`email` = 'b')
|
96
|
+
```
|
97
|
+
### (B || C) && A
|
98
|
+
```rb
|
99
|
+
User.where(B).or(C).where(A)
|
100
|
+
# =>
|
101
|
+
# SELECT `users`.* FROM `users`
|
102
|
+
# WHERE (`users`.`account` = 'a' OR `users`.`email` = 'b') AND `users`.`id` = 1
|
103
|
+
```
|
104
|
+
### A && B || A && C
|
105
|
+
```rb
|
106
|
+
User.where(A).where(B).or(User.where(A).where(C))
|
107
|
+
# =>
|
108
|
+
# SELECT `users`.* FROM `users`
|
109
|
+
# WHERE (`users`.`id` = 1 AND `users`.`account` = 'a' OR `users`.`id` = 1 AND `users`.`email` = 'b')
|
110
|
+
```
|
111
|
+
### A && B || C
|
112
|
+
```rb
|
113
|
+
User.where(A).where(B).or(C)
|
114
|
+
# =>
|
115
|
+
# SELECT `users`.* FROM `users`
|
116
|
+
# WHERE (`users`.`id` = 1 AND `users`.`account` = 'a' OR `users`.`email` = 'b')
|
117
|
+
```
|
118
|
+
|
85
119
|
## Development
|
86
120
|
|
87
121
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/rails_or.rb
CHANGED
@@ -29,6 +29,10 @@ class ActiveRecord::Relation
|
|
29
29
|
end
|
30
30
|
|
31
31
|
relation = rails_or_get_current_scope
|
32
|
+
if defined?(ActiveRecord::NullRelation) # Rails 3 does not have ActiveRecord::NullRelation
|
33
|
+
return other if relation.is_a?(ActiveRecord::NullRelation)
|
34
|
+
return relation if other.is_a?(ActiveRecord::NullRelation)
|
35
|
+
end
|
32
36
|
relation.send("#{combining}_values=", common.where_values)
|
33
37
|
relation.bind_values = common.bind_values
|
34
38
|
return relation
|
data/lib/rails_or/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_or
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- khiav reoy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
123
|
version: '0'
|
124
124
|
requirements: []
|
125
125
|
rubyforge_project:
|
126
|
-
rubygems_version: 2.
|
126
|
+
rubygems_version: 2.4.8
|
127
127
|
signing_key:
|
128
128
|
specification_version: 4
|
129
129
|
summary: 'Support && Add syntax sugar to #or query method.'
|