rails_or 1.0.1 → 1.1.0
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 +20 -7
- data/lib/rails_or.rb +12 -0
- data/lib/rails_or/version.rb +1 -1
- data/rails_or.gemspec +2 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ba1866dbfc59514dc65d0f0f52d88622fc53c89
|
4
|
+
data.tar.gz: 5e3c3b5676508f3c7460eb0c111ea19fd7179a5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c734ab55e58e714824a6c47c4b88232da7d16a87eae00e80bc46e55c43c125b6330fb2a6c6561297290c43f594297f311e13b4c634b84d8b26fd29af30f0669
|
7
|
+
data.tar.gz: ff5bd8170ce892c420b833e44b624f55dc8078bb50ff8ec372cb27fec558eabbe37edaf19ca9d1ca83debe5d9c6ee76d9a70b5b1db5a4475d890e17131ac1d84
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
# RailsOr
|
8
8
|
|
9
|
-
Support #or query method in Rails 3, 4, 5
|
9
|
+
Support && Add syntax sugar to #or query method in Rails 3, 4, 5.
|
10
10
|
|
11
11
|
## Installation
|
12
12
|
|
@@ -28,18 +28,31 @@ Or install it yourself as:
|
|
28
28
|
|
29
29
|
### Same as Rails 5's #or method
|
30
30
|
```rb
|
31
|
-
Person.where(:
|
31
|
+
Person.where(name: 'Pearl').or(Person.where(age: 24))
|
32
32
|
# is the same as
|
33
33
|
Person.where("name = ? OR age = ?", 'Pearl', 24)
|
34
34
|
```
|
35
35
|
|
36
|
-
###
|
36
|
+
### More Easy to use
|
37
|
+
No need to repeat writing `Model.joins(XXX).where(...)`
|
37
38
|
```rb
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
# before
|
40
|
+
User.joins(:posts).where(id: 2)
|
41
|
+
.or(User.joins(:posts).where('posts.title = ?',"title"))
|
42
|
+
.or(User.joins(:posts).where('posts.created_at > ?', 1.day.ago))
|
43
|
+
# after
|
44
|
+
User.joins(:posts).where(id: 2)
|
45
|
+
.or('posts.title': "title")
|
46
|
+
.or('posts.created_at > ?', 1.day.ago)
|
42
47
|
```
|
48
|
+
Support passing `Hash` / `Array` / `String` as parameters
|
49
|
+
```rb
|
50
|
+
Person.where(name: 'Pearl').or(age: 24)
|
51
|
+
Person.where(name: 'Pearl').or(['age = ?', 24])
|
52
|
+
Person.where(name: 'Pearl').or('age = ?', 24)
|
53
|
+
Person.where(name: 'Pearl').or('age = 24')
|
54
|
+
```
|
55
|
+
|
43
56
|
|
44
57
|
|
45
58
|
## Development
|
data/lib/rails_or.rb
CHANGED
@@ -29,6 +29,18 @@ class ActiveRecord::Relation
|
|
29
29
|
return self
|
30
30
|
end
|
31
31
|
end
|
32
|
+
if Gem::Version.new(Rails::VERSION::STRING) < Gem::Version.new('4.0.0')
|
33
|
+
def or_not(*args)
|
34
|
+
raise 'This method is not support in Rails 3'
|
35
|
+
end
|
36
|
+
else
|
37
|
+
def or_not(*args)
|
38
|
+
return self.or(klass.where.not(*args))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
def or_having(*args)
|
42
|
+
self.or(klass.having(*args))
|
43
|
+
end
|
32
44
|
private
|
33
45
|
def parse_or_parameter(*other)
|
34
46
|
other = other.first if other.size == 1
|
data/lib/rails_or/version.rb
CHANGED
data/rails_or.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["khiav reoy"]
|
10
10
|
spec.email = ["mrtmrt15xn@yahoo.com.tw"]
|
11
11
|
|
12
|
-
spec.summary = %q{Support
|
13
|
-
spec.description = %q{Support
|
12
|
+
spec.summary = %q{Support && Add syntax sugar to #or query method.}
|
13
|
+
spec.description = %q{Support && Add syntax sugar to #or query method in Rails 3, 4, 5.}
|
14
14
|
spec.homepage = "https://github.com/khiav223577/rails_or"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
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.0
|
4
|
+
version: 1.1.0
|
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-01-
|
11
|
+
date: 2017-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,7 +80,7 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '3'
|
83
|
-
description: 'Support
|
83
|
+
description: 'Support && Add syntax sugar to #or query method in Rails 3, 4, 5.'
|
84
84
|
email:
|
85
85
|
- mrtmrt15xn@yahoo.com.tw
|
86
86
|
executables: []
|
@@ -125,5 +125,5 @@ rubyforge_project:
|
|
125
125
|
rubygems_version: 2.4.8
|
126
126
|
signing_key:
|
127
127
|
specification_version: 4
|
128
|
-
summary: 'Support
|
128
|
+
summary: 'Support && Add syntax sugar to #or query method.'
|
129
129
|
test_files: []
|