rails_or 1.1.8 → 1.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/ruby.yml +62 -0
- data/.gitignore +10 -9
- data/.rubocop.yml +1227 -0
- data/CHANGELOG.md +77 -77
- data/CODE_OF_CONDUCT.md +48 -48
- data/LICENSE.txt +21 -21
- data/README.md +152 -133
- data/Rakefile +5 -5
- data/bin/console +3 -3
- data/bin/setup +8 -8
- data/gemfiles/3.2.gemfile +10 -13
- data/gemfiles/4.2.gemfile +10 -13
- data/gemfiles/5.0.gemfile +10 -13
- data/gemfiles/5.1.gemfile +10 -13
- data/gemfiles/5.2.gemfile +10 -0
- data/gemfiles/6.0.gemfile +10 -0
- data/gemfiles/6.1.gemfile +10 -0
- data/lib/rails_or.rb +63 -119
- data/lib/rails_or/active_record/extension.rb +52 -0
- data/lib/rails_or/patches/null_relation.rb +8 -0
- data/lib/rails_or/version.rb +3 -3
- data/lib/rails_or/where_binding_mixs.rb +38 -38
- data/rails_or.gemspec +43 -37
- metadata +26 -10
- data/.travis.yml +0 -21
data/CHANGELOG.md
CHANGED
@@ -1,77 +1,77 @@
|
|
1
|
-
|
2
|
-
### RailsOr [Unreleased]
|
3
|
-
|
4
|
-
- No changes.
|
5
|
-
|
6
|
-
### RailsOr [1.1.8] - (March 14, 2018)
|
7
|
-
|
8
|
-
- Fix missing from_clause when using #from and #none together [[#23](https://github.com/khiav223577/rails_or/pull/23)] @khiav223577
|
9
|
-
|
10
|
-
### RailsOr [1.1.7] - (September 12, 2017)
|
11
|
-
|
12
|
-
- Better Rails 5 Support. [[#21](https://github.com/khiav223577/rails_or/pull/21)] @khiav223577
|
13
|
-
|
14
|
-
### RailsOr [1.1.6] - (June 30, 2017)
|
15
|
-
|
16
|
-
- Supports `or` with `.none`. [[#20](https://github.com/khiav223577/rails_or/pull/20)] @khiav223577
|
17
|
-
<br><br>
|
18
|
-
|
19
|
-
### RailsOr [1.1.5] - (June 21, 2017)
|
20
|
-
|
21
|
-
- Fix bind values mismatch after merging common where values. [[#19](https://github.com/khiav223577/rails_or/pull/19)] @khiav223577
|
22
|
-
<br><br>
|
23
|
-
|
24
|
-
### RailsOr [1.1.4] - (April 1, 2017)
|
25
|
-
|
26
|
-
- Add more assertions for nested or. [[#17](https://github.com/khiav223577/rails_or/pull/17)] @khiav223577
|
27
|
-
- Restrict dependency to activerecord. [[#18](https://github.com/khiav223577/rails_or/pull/18)] @khiav223577
|
28
|
-
<br><br>
|
29
|
-
|
30
|
-
### RailsOr [1.1.3] - (February 23, 2017)
|
31
|
-
|
32
|
-
- Fixed nested or broken. [[#16](https://github.com/khiav223577/rails_or/pull/16)] @khiav223577
|
33
|
-
<br><br>
|
34
|
-
|
35
|
-
### RailsOr [1.1.2] - (February 14, 2017)
|
36
|
-
|
37
|
-
- Fixed if some gems change #all method's behavior. [[#14](https://github.com/khiav223577/rails_or/pull/14)] @khiav223577
|
38
|
-
<br><br>
|
39
|
-
|
40
|
-
### RailsOr [1.1.1] - (February 6, 2017)
|
41
|
-
|
42
|
-
- Fixed #or method fail between two has_many associations. [[#11](https://github.com/khiav223577/rails_or/pull/11)] @khiav223577
|
43
|
-
<br><br>
|
44
|
-
|
45
|
-
### RailsOr [1.1.0] - (January 6, 2017)
|
46
|
-
|
47
|
-
- Add #or_not method [[#6](https://github.com/khiav223577/rails_or/pull/6)] @khiav223577
|
48
|
-
- Add #or_having method [[#7](https://github.com/khiav223577/rails_or/pull/7)] @khiav223577
|
49
|
-
<br><br>
|
50
|
-
|
51
|
-
### RailsOr [1.0.1] - (January 4, 2017)
|
52
|
-
|
53
|
-
- Fixed disappear binding values in some syntax [[#5](https://github.com/khiav223577/rails_or/pull/5)] @khiav223577
|
54
|
-
<br><br>
|
55
|
-
|
56
|
-
### RailsOr [1.0.0] - (December 29, 2016)
|
57
|
-
|
58
|
-
- Support using Hash/Array/String as arguments [[#2](https://github.com/khiav223577/rails_or/pull/2)] @khiav223577
|
59
|
-
<br><br>
|
60
|
-
|
61
|
-
### RailsOr 0.0.1 - (December 28, 2016)
|
62
|
-
|
63
|
-
- Add #or method [[#1](https://github.com/khiav223577/rails_or/pull/1)] @khiav223577
|
64
|
-
<br><br>
|
65
|
-
|
66
|
-
[Unreleased]: https://github.com/khiav223577/rails_or/compare/v1.1.8...HEAD
|
67
|
-
[1.1.8]: https://github.com/khiav223577/rails_or/compare/v1.1.7...v1.1.8
|
68
|
-
[1.1.7]: https://github.com/khiav223577/rails_or/compare/v1.1.6...v1.1.7
|
69
|
-
[1.1.6]: https://github.com/khiav223577/rails_or/compare/v1.1.5...v1.1.6
|
70
|
-
[1.1.5]: https://github.com/khiav223577/rails_or/compare/v1.1.4...v1.1.5
|
71
|
-
[1.1.4]: https://github.com/khiav223577/rails_or/compare/v1.1.3...v1.1.4
|
72
|
-
[1.1.3]: https://github.com/khiav223577/rails_or/compare/v1.1.2...v1.1.3
|
73
|
-
[1.1.2]: https://github.com/khiav223577/rails_or/compare/v1.1.1...v1.1.2
|
74
|
-
[1.1.1]: https://github.com/khiav223577/rails_or/compare/v1.1.0...v1.1.1
|
75
|
-
[1.1.0]: https://github.com/khiav223577/rails_or/compare/v1.0.1...v1.1.0
|
76
|
-
[1.0.1]: https://github.com/khiav223577/rails_or/compare/v1.0.0...v1.0.1
|
77
|
-
[1.0.0]: https://github.com/khiav223577/rails_or/compare/v0.0.1...v1.0.0
|
1
|
+
|
2
|
+
### RailsOr [Unreleased]
|
3
|
+
|
4
|
+
- No changes.
|
5
|
+
|
6
|
+
### RailsOr [1.1.8] - (March 14, 2018)
|
7
|
+
|
8
|
+
- Fix missing from_clause when using #from and #none together [[#23](https://github.com/khiav223577/rails_or/pull/23)] @khiav223577
|
9
|
+
|
10
|
+
### RailsOr [1.1.7] - (September 12, 2017)
|
11
|
+
|
12
|
+
- Better Rails 5 Support. [[#21](https://github.com/khiav223577/rails_or/pull/21)] @khiav223577
|
13
|
+
|
14
|
+
### RailsOr [1.1.6] - (June 30, 2017)
|
15
|
+
|
16
|
+
- Supports `or` with `.none`. [[#20](https://github.com/khiav223577/rails_or/pull/20)] @khiav223577
|
17
|
+
<br><br>
|
18
|
+
|
19
|
+
### RailsOr [1.1.5] - (June 21, 2017)
|
20
|
+
|
21
|
+
- Fix bind values mismatch after merging common where values. [[#19](https://github.com/khiav223577/rails_or/pull/19)] @khiav223577
|
22
|
+
<br><br>
|
23
|
+
|
24
|
+
### RailsOr [1.1.4] - (April 1, 2017)
|
25
|
+
|
26
|
+
- Add more assertions for nested or. [[#17](https://github.com/khiav223577/rails_or/pull/17)] @khiav223577
|
27
|
+
- Restrict dependency to activerecord. [[#18](https://github.com/khiav223577/rails_or/pull/18)] @khiav223577
|
28
|
+
<br><br>
|
29
|
+
|
30
|
+
### RailsOr [1.1.3] - (February 23, 2017)
|
31
|
+
|
32
|
+
- Fixed nested or broken. [[#16](https://github.com/khiav223577/rails_or/pull/16)] @khiav223577
|
33
|
+
<br><br>
|
34
|
+
|
35
|
+
### RailsOr [1.1.2] - (February 14, 2017)
|
36
|
+
|
37
|
+
- Fixed if some gems change #all method's behavior. [[#14](https://github.com/khiav223577/rails_or/pull/14)] @khiav223577
|
38
|
+
<br><br>
|
39
|
+
|
40
|
+
### RailsOr [1.1.1] - (February 6, 2017)
|
41
|
+
|
42
|
+
- Fixed #or method fail between two has_many associations. [[#11](https://github.com/khiav223577/rails_or/pull/11)] @khiav223577
|
43
|
+
<br><br>
|
44
|
+
|
45
|
+
### RailsOr [1.1.0] - (January 6, 2017)
|
46
|
+
|
47
|
+
- Add #or_not method [[#6](https://github.com/khiav223577/rails_or/pull/6)] @khiav223577
|
48
|
+
- Add #or_having method [[#7](https://github.com/khiav223577/rails_or/pull/7)] @khiav223577
|
49
|
+
<br><br>
|
50
|
+
|
51
|
+
### RailsOr [1.0.1] - (January 4, 2017)
|
52
|
+
|
53
|
+
- Fixed disappear binding values in some syntax [[#5](https://github.com/khiav223577/rails_or/pull/5)] @khiav223577
|
54
|
+
<br><br>
|
55
|
+
|
56
|
+
### RailsOr [1.0.0] - (December 29, 2016)
|
57
|
+
|
58
|
+
- Support using Hash/Array/String as arguments [[#2](https://github.com/khiav223577/rails_or/pull/2)] @khiav223577
|
59
|
+
<br><br>
|
60
|
+
|
61
|
+
### RailsOr 0.0.1 - (December 28, 2016)
|
62
|
+
|
63
|
+
- Add #or method [[#1](https://github.com/khiav223577/rails_or/pull/1)] @khiav223577
|
64
|
+
<br><br>
|
65
|
+
|
66
|
+
[Unreleased]: https://github.com/khiav223577/rails_or/compare/v1.1.8...HEAD
|
67
|
+
[1.1.8]: https://github.com/khiav223577/rails_or/compare/v1.1.7...v1.1.8
|
68
|
+
[1.1.7]: https://github.com/khiav223577/rails_or/compare/v1.1.6...v1.1.7
|
69
|
+
[1.1.6]: https://github.com/khiav223577/rails_or/compare/v1.1.5...v1.1.6
|
70
|
+
[1.1.5]: https://github.com/khiav223577/rails_or/compare/v1.1.4...v1.1.5
|
71
|
+
[1.1.4]: https://github.com/khiav223577/rails_or/compare/v1.1.3...v1.1.4
|
72
|
+
[1.1.3]: https://github.com/khiav223577/rails_or/compare/v1.1.2...v1.1.3
|
73
|
+
[1.1.2]: https://github.com/khiav223577/rails_or/compare/v1.1.1...v1.1.2
|
74
|
+
[1.1.1]: https://github.com/khiav223577/rails_or/compare/v1.1.0...v1.1.1
|
75
|
+
[1.1.0]: https://github.com/khiav223577/rails_or/compare/v1.0.1...v1.1.0
|
76
|
+
[1.0.1]: https://github.com/khiav223577/rails_or/compare/v1.0.0...v1.0.1
|
77
|
+
[1.0.0]: https://github.com/khiav223577/rails_or/compare/v0.0.1...v1.0.0
|
data/CODE_OF_CONDUCT.md
CHANGED
@@ -1,49 +1,49 @@
|
|
1
|
-
# Contributor Code of Conduct
|
2
|
-
|
3
|
-
As contributors and maintainers of this project, and in the interest of
|
4
|
-
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
-
contribute through reporting issues, posting feature requests, updating
|
6
|
-
documentation, submitting pull requests or patches, and other activities.
|
7
|
-
|
8
|
-
We are committed to making participation in this project a harassment-free
|
9
|
-
experience for everyone, regardless of level of experience, gender, gender
|
10
|
-
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
-
body size, race, ethnicity, age, religion, or nationality.
|
12
|
-
|
13
|
-
Examples of unacceptable behavior by participants include:
|
14
|
-
|
15
|
-
* The use of sexualized language or imagery
|
16
|
-
* Personal attacks
|
17
|
-
* Trolling or insulting/derogatory comments
|
18
|
-
* Public or private harassment
|
19
|
-
* Publishing other's private information, such as physical or electronic
|
20
|
-
addresses, without explicit permission
|
21
|
-
* Other unethical or unprofessional conduct
|
22
|
-
|
23
|
-
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
-
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
-
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
-
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
-
threatening, offensive, or harmful.
|
28
|
-
|
29
|
-
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
-
fairly and consistently applying these principles to every aspect of managing
|
31
|
-
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
-
Conduct may be permanently removed from the project team.
|
33
|
-
|
34
|
-
This code of conduct applies both within project spaces and in public spaces
|
35
|
-
when an individual is representing the project or its community.
|
36
|
-
|
37
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
-
reported by contacting a project maintainer at mrtmrt15xn@yahoo.com.tw. All
|
39
|
-
complaints will be reviewed and investigated and will result in a response that
|
40
|
-
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
-
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
-
incident.
|
43
|
-
|
44
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
-
version 1.3.0, available at
|
46
|
-
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
-
|
48
|
-
[homepage]: http://contributor-covenant.org
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at mrtmrt15xn@yahoo.com.tw. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
49
|
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/LICENSE.txt
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2016 khiav reoy
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 khiav reoy
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,133 +1,152 @@
|
|
1
|
-
# RailsOr
|
2
|
-
|
3
|
-
[![Gem Version](https://img.shields.io/gem/v/rails_or.svg?style=flat)](https://rubygems.org/gems/rails_or)
|
4
|
-
[![Build Status](https://
|
5
|
-
[![RubyGems](http://img.shields.io/gem/dt/rails_or.svg?style=flat)](https://rubygems.org/gems/rails_or)
|
6
|
-
[![Code Climate](https://codeclimate.com/github/khiav223577/rails_or/badges/gpa.svg)](https://codeclimate.com/github/khiav223577/rails_or)
|
7
|
-
[![Test Coverage](https://codeclimate.com/github/khiav223577/rails_or/badges/coverage.svg)](https://codeclimate.com/github/khiav223577/rails_or/coverage)
|
8
|
-
|
9
|
-
`rails_or` is a Ruby Gem for
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
$
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
#
|
50
|
-
User.
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
(
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
```
|
84
|
-
|
85
|
-
##
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
```rb
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
#
|
115
|
-
|
116
|
-
|
117
|
-
```
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
1
|
+
# RailsOr
|
2
|
+
|
3
|
+
[![Gem Version](https://img.shields.io/gem/v/rails_or.svg?style=flat)](https://rubygems.org/gems/rails_or)
|
4
|
+
[![Build Status](https://github.com/khiav223577/rails_or/workflows/Ruby/badge.svg)](https://github.com/khiav223577/rails_or/actions)
|
5
|
+
[![RubyGems](http://img.shields.io/gem/dt/rails_or.svg?style=flat)](https://rubygems.org/gems/rails_or)
|
6
|
+
[![Code Climate](https://codeclimate.com/github/khiav223577/rails_or/badges/gpa.svg)](https://codeclimate.com/github/khiav223577/rails_or)
|
7
|
+
[![Test Coverage](https://codeclimate.com/github/khiav223577/rails_or/badges/coverage.svg)](https://codeclimate.com/github/khiav223577/rails_or/coverage)
|
8
|
+
|
9
|
+
`rails_or` is a Ruby Gem for you to write cleaner `OR` query.
|
10
|
+
|
11
|
+
It will use built-in `or` method, which was added in Rails 5, when possible, so that you don't need to worry about that it will polulate `active_model`. Otherwise, it implements `or` method for Rails 3 and Rails 4.
|
12
|
+
|
13
|
+
## Supports
|
14
|
+
- Ruby 2.2 ~ 2.7
|
15
|
+
- Rails 3.2, 4.2, 5.0, 5.1, 5.2, 6.0, 6.1
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
Add this line to your application's Gemfile:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
gem 'rails_or'
|
23
|
+
```
|
24
|
+
|
25
|
+
And then execute:
|
26
|
+
|
27
|
+
$ bundle
|
28
|
+
|
29
|
+
Or install it yourself as:
|
30
|
+
|
31
|
+
$ gem install rails_or
|
32
|
+
|
33
|
+
## Usage
|
34
|
+
|
35
|
+
### Same as Rails 5's #or method
|
36
|
+
```rb
|
37
|
+
Person.where(name: 'Pearl').or(Person.where(age: 24))
|
38
|
+
|
39
|
+
# is the same as
|
40
|
+
Person.where("name = ? OR age = ?", 'Pearl', 24)
|
41
|
+
```
|
42
|
+
|
43
|
+
### Clearer Syntax
|
44
|
+
|
45
|
+
```rb
|
46
|
+
# Before
|
47
|
+
user = User.where(account: account).or(User.where(email: account)).take
|
48
|
+
|
49
|
+
# After
|
50
|
+
user = User.where(account: account).or(email: account).take
|
51
|
+
```
|
52
|
+
|
53
|
+
```rb
|
54
|
+
# Before
|
55
|
+
class Post < ActiveRecord::Base
|
56
|
+
scope :not_expired, ->{ where(end_time: nil).or(Post.where('end_time > ?', Time.now)) }
|
57
|
+
end
|
58
|
+
|
59
|
+
# After
|
60
|
+
class Post < ActiveRecord::Base
|
61
|
+
scope :not_expired, ->{ where(end_time: nil).or('end_time > ?', Time.now) }
|
62
|
+
end
|
63
|
+
```
|
64
|
+
|
65
|
+
|
66
|
+
No need to repeat writing `Model.joins(XXX).where(...)`
|
67
|
+
```rb
|
68
|
+
# Before
|
69
|
+
User.joins(:posts).where(id: 2)
|
70
|
+
.or(User.joins(:posts).where('posts.title = ?',"title"))
|
71
|
+
.or(User.joins(:posts).where('posts.created_at > ?', 1.day.ago))
|
72
|
+
# After
|
73
|
+
User.joins(:posts).where(id: 2)
|
74
|
+
.or('posts.title': "title")
|
75
|
+
.or('posts.created_at > ?', 1.day.ago)
|
76
|
+
```
|
77
|
+
Support passing `Hash` / `Array` / `String` as parameters
|
78
|
+
```rb
|
79
|
+
Person.where(name: 'Pearl').or(age: 24)
|
80
|
+
Person.where(name: 'Pearl').or(['age = ?', 24])
|
81
|
+
Person.where(name: 'Pearl').or('age = ?', 24)
|
82
|
+
Person.where(name: 'Pearl').or('age = 24')
|
83
|
+
```
|
84
|
+
|
85
|
+
## Other convenient methods
|
86
|
+
|
87
|
+
### or_not
|
88
|
+
(Only supports in Rails 4+)
|
89
|
+
```rb
|
90
|
+
Company.where.not(logo_image1: nil)
|
91
|
+
.or_not(logo_image2: nil)
|
92
|
+
.or_not(logo_image3: nil)
|
93
|
+
.or_not(logo_image4: nil)
|
94
|
+
```
|
95
|
+
|
96
|
+
### or_having
|
97
|
+
|
98
|
+
```rb
|
99
|
+
Order.group('user_id')
|
100
|
+
.having('SUM(price) > 1000')
|
101
|
+
.or_having('COUNT(*) > 10')
|
102
|
+
```
|
103
|
+
|
104
|
+
## Examples
|
105
|
+
|
106
|
+
Let `A = { id: 1 }`, `B = { account: 'tester' }`, and `C = { email: 'test@example.com' }`
|
107
|
+
|
108
|
+
### A && (B || C)
|
109
|
+
```rb
|
110
|
+
u = User.where(A)
|
111
|
+
u.where(B).or(u.where(C))
|
112
|
+
# =>
|
113
|
+
# SELECT `users`.* FROM `users`
|
114
|
+
# WHERE `users`.`id` = 1 AND (`users`.`account` = 'tester' OR `users`.`email` = 'test@example.com')
|
115
|
+
```
|
116
|
+
### (B || C) && A
|
117
|
+
```rb
|
118
|
+
User.where(B).or(C).where(A)
|
119
|
+
# =>
|
120
|
+
# SELECT `users`.* FROM `users`
|
121
|
+
# WHERE (`users`.`account` = 'tester' OR `users`.`email` = 'test@example.com') AND `users`.`id` = 1
|
122
|
+
```
|
123
|
+
### A && B || A && C
|
124
|
+
```rb
|
125
|
+
User.where(A).where(B).or(User.where(A).where(C))
|
126
|
+
# =>
|
127
|
+
# SELECT `users`.* FROM `users`
|
128
|
+
# WHERE (`users`.`id` = 1 AND `users`.`account` = 'tester' OR `users`.`id` = 1 AND `users`.`email` = 'test@example.com')
|
129
|
+
```
|
130
|
+
### A && B || C
|
131
|
+
```rb
|
132
|
+
User.where(A).where(B).or(C)
|
133
|
+
# =>
|
134
|
+
# SELECT `users`.* FROM `users`
|
135
|
+
# WHERE (`users`.`id` = 1 AND `users`.`account` = 'tester' OR `users`.`email` = 'test@example.com')
|
136
|
+
```
|
137
|
+
|
138
|
+
## Development
|
139
|
+
|
140
|
+
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.
|
141
|
+
|
142
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
143
|
+
|
144
|
+
## Contributing
|
145
|
+
|
146
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/khiav223577/rails_or. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
147
|
+
|
148
|
+
|
149
|
+
## License
|
150
|
+
|
151
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
152
|
+
|