rails_or 1.1.1 → 1.1.2

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: ba1ae5b2bc25a6e83952a0057393d7ab89d118a5
4
- data.tar.gz: ebabbac16cb6e1e16d856b0ad4af23040f65c804
3
+ metadata.gz: eb04bc9b28a161af5935120a35ed5a27a34293cb
4
+ data.tar.gz: 43af4e319dd0f7d77b00c7c7f25ec5444b4ea0b3
5
5
  SHA512:
6
- metadata.gz: 92650ae5783ed9c2060d29d96533eb7f6b593b71b25864cccd434fd1018e61d9dd99cc1a67a38f1d392864199b7863217b96ce14488988069b122b9cbbf987c9
7
- data.tar.gz: 2f0006c7e3ad9fa18255c68ec39fbb5ad8f7911b8314f93501c42c5381ef8ebba3a21c76abae3643d3217ff385c4efc4f77592ddaa814d92a6ea139b75f2467b
6
+ metadata.gz: 2326a06c3c6cbab54864b790018f736818abdff7a0a8b9975e801fe1fef4e7ec40caee235fa3642c484c9096eaefc208400e7a37fa1761d81562b1b7a9fc44ec
7
+ data.tar.gz: d40665dcdbddd2886d4eba9bfbefb42b39b81b186652811c49e09a77beaaa30e1ed741e6eeba1a3f20a92c2ffdf3dca036965a2525d36d2e042fd6d8bd954261
data/lib/rails_or.rb CHANGED
@@ -2,6 +2,7 @@ require "rails_or/version"
2
2
  require 'active_record'
3
3
 
4
4
  class ActiveRecord::Relation
5
+ IS_RAILS3_FLAG = Gem::Version.new(ActiveRecord::VERSION::STRING) < Gem::Version.new('4.0.0')
5
6
  if method_defined?(:or)
6
7
  alias rails5_or or
7
8
  def or(*other)
@@ -29,14 +30,9 @@ class ActiveRecord::Relation
29
30
  return relation
30
31
  end
31
32
  end
32
- if Gem::Version.new(ActiveRecord::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
33
+ def or_not(*args)
34
+ raise 'This method is not support in Rails 3' if IS_RAILS3_FLAG
35
+ return self.or(klass.where.not(*args))
40
36
  end
41
37
  def or_having(*args)
42
38
  self.or(klass.having(*args))
@@ -51,10 +47,11 @@ private
51
47
  else ; other
52
48
  end
53
49
  end
54
- RAILS_OR_GET_CURRENT_SCOPE_METHOD = (Gem::Version.new(ActiveRecord::VERSION::STRING) < Gem::Version.new('4.0.0') ? :clone : :all)
55
50
  def rails_or_get_current_scope
51
+ return self.clone if IS_RAILS3_FLAG
56
52
  #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)
53
+ #return self.all # <- cannot use this because some gem changes this method's behavior
54
+ return (self.current_scope || self.default_scoped).clone
58
55
  end
59
56
  end
60
57
  class ActiveRecord::Base
@@ -1,3 +1,3 @@
1
1
  module RailsOr
2
- VERSION = "1.1.1"
2
+ VERSION = "1.1.2"
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.1
4
+ version: 1.1.2
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-02-06 00:00:00.000000000 Z
11
+ date: 2017-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler