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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0434d1cac1c04acacf74b933dff00a190162cdd9
4
- data.tar.gz: 8af3108d409a281eb8cab6955eedc4ddb11c76de
3
+ metadata.gz: 8f9c88ae5f5c4ed9ac8fb2cfc64dbe22be904da8
4
+ data.tar.gz: 639ff10eb8da02ab73d0a5701b75c2fa5a438b08
5
5
  SHA512:
6
- metadata.gz: f422a1b8d235ddad25daf0beb82882569b4742bda3ab521b6f802d956d0dbdf889f7d1156882c3cf2b80113eb48bdaaa5e7ee33cf2299c293ac72c90112098d0
7
- data.tar.gz: 5c5e512521f05cb1fdd817005adc14439b0caa413b41d82db300d9928eb0853c8cf066c10fa21dc088ea96a12cf32c1ca4cc511c765a70175f126d4d85a40331
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
- ### Other convenient methods
66
+ ## Other convenient methods
67
67
 
68
- #### or_not
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
- #### or_having
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.
@@ -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
@@ -1,3 +1,3 @@
1
1
  module RailsOr
2
- VERSION = "1.1.5"
2
+ VERSION = "1.1.6"
3
3
  end
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.5
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-06-21 00:00:00.000000000 Z
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.6.8
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.'