rails_or 1.0.1 → 1.1.0

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: e7b1ec771bf9f285557e672b4ef9f35c373d3e8f
4
- data.tar.gz: a7e535164ba64cb7e162acd5913e7691a6e10154
3
+ metadata.gz: 9ba1866dbfc59514dc65d0f0f52d88622fc53c89
4
+ data.tar.gz: 5e3c3b5676508f3c7460eb0c111ea19fd7179a5c
5
5
  SHA512:
6
- metadata.gz: 87a9ee331fccfe976f1cd71206bbee456b339a8f0125441b79d95b0457a129547e492db033188baa58c4b57e309c8217833438daf23a85b2dcd091bf9481d354
7
- data.tar.gz: 14b69f148cab20a19821484b8204295faefa98652a62aa4397d175d62d08e5494a3f86b877b80c9a48ab1e74d04945fe994b116b4dd540701a8be474fb4d1559
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(:name => 'Pearl').or(Person.where(:age => 24))
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
- ### Support using Hash/Array/String as arguments
36
+ ### More Easy to use
37
+ No need to repeat writing `Model.joins(XXX).where(...)`
37
38
  ```rb
38
- Person.where(:name => 'Pearl').or(:age => 24)
39
- Person.where(:name => 'Pearl').or(['age = ?', 24])
40
- Person.where(:name => 'Pearl').or('age = ?', 24)
41
- Person.where(:name => 'Pearl').or('age = 24')
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
@@ -1,3 +1,3 @@
1
1
  module RailsOr
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
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 and entend #or query method.}
13
- spec.description = %q{Support and entend #or query method in Rails 3, 4, 5.}
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.1
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-04 00:00:00.000000000 Z
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 and entend #or query method in Rails 3, 4, 5.'
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 and entend #or query method.'
128
+ summary: 'Support && Add syntax sugar to #or query method.'
129
129
  test_files: []