rails_or 1.1.0 → 1.1.1
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/README.md +3 -1
- data/gemfiles/3.2.gemfile +1 -1
- data/gemfiles/4.2.gemfile +1 -1
- data/gemfiles/5.0.gemfile +1 -1
- data/lib/rails_or.rb +13 -8
- data/lib/rails_or/version.rb +1 -1
- data/rails_or.gemspec +1 -1
- metadata +4 -5
- data/gemfiles/4.2.gemfile.lock +0 -127
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba1ae5b2bc25a6e83952a0057393d7ab89d118a5
|
4
|
+
data.tar.gz: ebabbac16cb6e1e16d856b0ad4af23040f65c804
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92650ae5783ed9c2060d29d96533eb7f6b593b71b25864cccd434fd1018e61d9dd99cc1a67a38f1d392864199b7863217b96ce14488988069b122b9cbbf987c9
|
7
|
+
data.tar.gz: 2f0006c7e3ad9fa18255c68ec39fbb5ad8f7911b8314f93501c42c5381ef8ebba3a21c76abae3643d3217ff385c4efc4f77592ddaa814d92a6ea139b75f2467b
|
data/README.md
CHANGED
@@ -8,6 +8,8 @@
|
|
8
8
|
|
9
9
|
Support && Add syntax sugar to #or query method in Rails 3, 4, 5.
|
10
10
|
|
11
|
+
Allowing use of the OR operator to combine WHERE or HAVING clauses.
|
12
|
+
|
11
13
|
## Installation
|
12
14
|
|
13
15
|
Add this line to your application's Gemfile:
|
@@ -33,7 +35,7 @@ Person.where(name: 'Pearl').or(Person.where(age: 24))
|
|
33
35
|
Person.where("name = ? OR age = ?", 'Pearl', 24)
|
34
36
|
```
|
35
37
|
|
36
|
-
###
|
38
|
+
### Easier to use
|
37
39
|
No need to repeat writing `Model.joins(XXX).where(...)`
|
38
40
|
```rb
|
39
41
|
# before
|
data/gemfiles/3.2.gemfile
CHANGED
data/gemfiles/4.2.gemfile
CHANGED
data/gemfiles/5.0.gemfile
CHANGED
data/lib/rails_or.rb
CHANGED
@@ -1,16 +1,15 @@
|
|
1
1
|
require "rails_or/version"
|
2
|
-
require 'rails'
|
3
2
|
require 'active_record'
|
4
3
|
|
5
4
|
class ActiveRecord::Relation
|
6
5
|
if method_defined?(:or)
|
7
6
|
alias rails5_or or
|
8
7
|
def or(*other)
|
9
|
-
return rails5_or(
|
8
|
+
return rails5_or(rails_or_parse_parameter(*other))
|
10
9
|
end
|
11
10
|
else
|
12
11
|
def or(*other)
|
13
|
-
other =
|
12
|
+
other = rails_or_parse_parameter(*other)
|
14
13
|
combining = group_values.any? ? :having : :where
|
15
14
|
left_values = send("#{combining}_values")
|
16
15
|
right_values = other.send("#{combining}_values")
|
@@ -24,12 +23,13 @@ class ActiveRecord::Relation
|
|
24
23
|
theirs = [Arel::Nodes::And.new(theirs)] if theirs.size > 1
|
25
24
|
common << Arel::Nodes::Or.new(mine.first, theirs.first)
|
26
25
|
end
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
relation = rails_or_get_current_scope
|
27
|
+
relation.send("#{combining}_values=", common)
|
28
|
+
relation.bind_values = self.bind_values + other.bind_values
|
29
|
+
return relation
|
30
30
|
end
|
31
31
|
end
|
32
|
-
if Gem::Version.new(
|
32
|
+
if Gem::Version.new(ActiveRecord::VERSION::STRING) < Gem::Version.new('4.0.0')
|
33
33
|
def or_not(*args)
|
34
34
|
raise 'This method is not support in Rails 3'
|
35
35
|
end
|
@@ -42,7 +42,7 @@ class ActiveRecord::Relation
|
|
42
42
|
self.or(klass.having(*args))
|
43
43
|
end
|
44
44
|
private
|
45
|
-
def
|
45
|
+
def rails_or_parse_parameter(*other)
|
46
46
|
other = other.first if other.size == 1
|
47
47
|
case other
|
48
48
|
when Hash ; klass.where(other)
|
@@ -51,6 +51,11 @@ private
|
|
51
51
|
else ; other
|
52
52
|
end
|
53
53
|
end
|
54
|
+
RAILS_OR_GET_CURRENT_SCOPE_METHOD = (Gem::Version.new(ActiveRecord::VERSION::STRING) < Gem::Version.new('4.0.0') ? :clone : :all)
|
55
|
+
def rails_or_get_current_scope
|
56
|
+
#ref: https://github.com/rails/rails/blob/17ef58db1776a795c9f9e31a1634db7bcdc3ecdf/activerecord/lib/active_record/scoping/named.rb#L26
|
57
|
+
return self.send(RAILS_OR_GET_CURRENT_SCOPE_METHOD)
|
58
|
+
end
|
54
59
|
end
|
55
60
|
class ActiveRecord::Base
|
56
61
|
def self.or(*args)
|
data/lib/rails_or/version.rb
CHANGED
data/rails_or.gemspec
CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.require_paths = ["lib"]
|
29
29
|
|
30
30
|
spec.add_development_dependency "bundler", "~> 1.11"
|
31
|
-
spec.add_development_dependency "rake", "~>
|
31
|
+
spec.add_development_dependency "rake", "~> 12.0"
|
32
32
|
spec.add_development_dependency "sqlite3", "~> 1.3"
|
33
33
|
spec.add_development_dependency "minitest", "~> 5.0"
|
34
34
|
|
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.1
|
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-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '12.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '12.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: sqlite3
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -97,7 +97,6 @@ files:
|
|
97
97
|
- bin/setup
|
98
98
|
- gemfiles/3.2.gemfile
|
99
99
|
- gemfiles/4.2.gemfile
|
100
|
-
- gemfiles/4.2.gemfile.lock
|
101
100
|
- gemfiles/5.0.gemfile
|
102
101
|
- lib/rails_or.rb
|
103
102
|
- lib/rails_or/version.rb
|
data/gemfiles/4.2.gemfile.lock
DELETED
@@ -1,127 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: ../
|
3
|
-
specs:
|
4
|
-
rails_or (0.0.1)
|
5
|
-
rails (>= 3)
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: https://rubygems.org/
|
9
|
-
specs:
|
10
|
-
actionmailer (4.2.7.1)
|
11
|
-
actionpack (= 4.2.7.1)
|
12
|
-
actionview (= 4.2.7.1)
|
13
|
-
activejob (= 4.2.7.1)
|
14
|
-
mail (~> 2.5, >= 2.5.4)
|
15
|
-
rails-dom-testing (~> 1.0, >= 1.0.5)
|
16
|
-
actionpack (4.2.7.1)
|
17
|
-
actionview (= 4.2.7.1)
|
18
|
-
activesupport (= 4.2.7.1)
|
19
|
-
rack (~> 1.6)
|
20
|
-
rack-test (~> 0.6.2)
|
21
|
-
rails-dom-testing (~> 1.0, >= 1.0.5)
|
22
|
-
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
23
|
-
actionview (4.2.7.1)
|
24
|
-
activesupport (= 4.2.7.1)
|
25
|
-
builder (~> 3.1)
|
26
|
-
erubis (~> 2.7.0)
|
27
|
-
rails-dom-testing (~> 1.0, >= 1.0.5)
|
28
|
-
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
29
|
-
activejob (4.2.7.1)
|
30
|
-
activesupport (= 4.2.7.1)
|
31
|
-
globalid (>= 0.3.0)
|
32
|
-
activemodel (4.2.7.1)
|
33
|
-
activesupport (= 4.2.7.1)
|
34
|
-
builder (~> 3.1)
|
35
|
-
activerecord (4.2.7.1)
|
36
|
-
activemodel (= 4.2.7.1)
|
37
|
-
activesupport (= 4.2.7.1)
|
38
|
-
arel (~> 6.0)
|
39
|
-
activesupport (4.2.7.1)
|
40
|
-
i18n (~> 0.7)
|
41
|
-
json (~> 1.7, >= 1.7.7)
|
42
|
-
minitest (~> 5.1)
|
43
|
-
thread_safe (~> 0.3, >= 0.3.4)
|
44
|
-
tzinfo (~> 1.1)
|
45
|
-
arel (6.0.4)
|
46
|
-
builder (3.2.2)
|
47
|
-
codeclimate-test-reporter (1.0.3)
|
48
|
-
simplecov
|
49
|
-
concurrent-ruby (1.0.4)
|
50
|
-
docile (1.1.5)
|
51
|
-
erubis (2.7.0)
|
52
|
-
globalid (0.3.7)
|
53
|
-
activesupport (>= 4.1.0)
|
54
|
-
i18n (0.7.0)
|
55
|
-
json (1.8.3)
|
56
|
-
loofah (2.0.3)
|
57
|
-
nokogiri (>= 1.5.9)
|
58
|
-
mail (2.6.4)
|
59
|
-
mime-types (>= 1.16, < 4)
|
60
|
-
mime-types (3.1)
|
61
|
-
mime-types-data (~> 3.2015)
|
62
|
-
mime-types-data (3.2016.0521)
|
63
|
-
mini_portile2 (2.1.0)
|
64
|
-
minitest (5.10.1)
|
65
|
-
nokogiri (1.7.0)
|
66
|
-
mini_portile2 (~> 2.1.0)
|
67
|
-
rack (1.6.5)
|
68
|
-
rack-test (0.6.3)
|
69
|
-
rack (>= 1.0)
|
70
|
-
rails (4.2.7.1)
|
71
|
-
actionmailer (= 4.2.7.1)
|
72
|
-
actionpack (= 4.2.7.1)
|
73
|
-
actionview (= 4.2.7.1)
|
74
|
-
activejob (= 4.2.7.1)
|
75
|
-
activemodel (= 4.2.7.1)
|
76
|
-
activerecord (= 4.2.7.1)
|
77
|
-
activesupport (= 4.2.7.1)
|
78
|
-
bundler (>= 1.3.0, < 2.0)
|
79
|
-
railties (= 4.2.7.1)
|
80
|
-
sprockets-rails
|
81
|
-
rails-deprecated_sanitizer (1.0.3)
|
82
|
-
activesupport (>= 4.2.0.alpha)
|
83
|
-
rails-dom-testing (1.0.8)
|
84
|
-
activesupport (>= 4.2.0.beta, < 5.0)
|
85
|
-
nokogiri (~> 1.6)
|
86
|
-
rails-deprecated_sanitizer (>= 1.0.1)
|
87
|
-
rails-html-sanitizer (1.0.3)
|
88
|
-
loofah (~> 2.0)
|
89
|
-
railties (4.2.7.1)
|
90
|
-
actionpack (= 4.2.7.1)
|
91
|
-
activesupport (= 4.2.7.1)
|
92
|
-
rake (>= 0.8.7)
|
93
|
-
thor (>= 0.18.1, < 2.0)
|
94
|
-
rake (10.5.0)
|
95
|
-
simplecov (0.12.0)
|
96
|
-
docile (~> 1.1.0)
|
97
|
-
json (>= 1.8, < 3)
|
98
|
-
simplecov-html (~> 0.10.0)
|
99
|
-
simplecov-html (0.10.0)
|
100
|
-
sprockets (3.7.1)
|
101
|
-
concurrent-ruby (~> 1.0)
|
102
|
-
rack (> 1, < 3)
|
103
|
-
sprockets-rails (3.2.0)
|
104
|
-
actionpack (>= 4.0)
|
105
|
-
activesupport (>= 4.0)
|
106
|
-
sprockets (>= 3.0.0)
|
107
|
-
sqlite3 (1.3.12)
|
108
|
-
thor (0.19.4)
|
109
|
-
thread_safe (0.3.5)
|
110
|
-
tzinfo (1.2.2)
|
111
|
-
thread_safe (~> 0.1)
|
112
|
-
|
113
|
-
PLATFORMS
|
114
|
-
ruby
|
115
|
-
|
116
|
-
DEPENDENCIES
|
117
|
-
bundler (~> 1.11)
|
118
|
-
codeclimate-test-reporter (~> 1.0.0)
|
119
|
-
minitest (~> 5.0)
|
120
|
-
rails (~> 4.2)
|
121
|
-
rails_or!
|
122
|
-
rake (~> 10.0)
|
123
|
-
simplecov
|
124
|
-
sqlite3 (~> 1.3)
|
125
|
-
|
126
|
-
BUNDLED WITH
|
127
|
-
1.11.2
|