everywhere 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,11 +6,78 @@ module ActiveRecord
6
6
  class << self
7
7
  include Everywhere::Util
8
8
 
9
- def build_from_hash_with_not_and_like_and_not_like(engine, attributes, default_table)
9
+ # >= 3.2.4, >= 3.1.5
10
+ if ActiveRecord::PredicateBuilder.method(:build_from_hash).arity == -4
11
+ def build_from_hash_with_not_and_like_and_not_like(engine, attributes, default_table, allow_table_name = true)
12
+ attributes_with_not_and_like_and_not_like = {}
13
+ attributes.each do |column, value|
14
+ # {not: {key: value}}
15
+ if column.in?([:not, :like, :not_like])
16
+ value.each do |k, v|
17
+ attributes_with_not_and_like_and_not_like["#{k}__#{column}__"] = v
18
+ end
19
+ else
20
+ attributes_with_not_and_like_and_not_like[column] = value
21
+ end
22
+ end
23
+ build_from_hash_without_not_and_like_and_not_like(engine, attributes_with_not_and_like_and_not_like, default_table, allow_table_name).map do |rel|
24
+ if rel.left.name.to_s.ends_with? '__not__'
25
+ rel.left.name = rel.left.name.to_s.sub(/__not__$/, '').to_sym
26
+ negate rel
27
+ elsif rel.left.name.to_s.ends_with? '__like__'
28
+ rel.left.name = rel.left.name.to_s.sub(/__like__$/, '').to_sym
29
+ Arel::Nodes::Matches.new rel.left, rel.right
30
+ elsif rel.left.name.to_s.ends_with? '__not_like__'
31
+ rel.left.name = rel.left.name.to_s.sub(/__not_like__$/, '').to_sym
32
+ Arel::Nodes::DoesNotMatch.new rel.left, rel.right
33
+ else
34
+ rel
35
+ end
36
+ end
37
+ end
38
+ # < 3.2.4, < 3.1.5, >= 4.0?
39
+ else
40
+ def build_from_hash_with_not_and_like_and_not_like(engine, attributes, default_table)
41
+ attributes_with_not_and_like_and_not_like = {}
42
+ attributes.each do |column, value|
43
+ # {not: {key: value}}
44
+ if column.in?([:not, :like, :not_like])
45
+ value.each do |k, v|
46
+ attributes_with_not_and_like_and_not_like["#{k}__#{column}__"] = v
47
+ end
48
+ else
49
+ attributes_with_not_and_like_and_not_like[column] = value
50
+ end
51
+ end
52
+ build_from_hash_without_not_and_like_and_not_like(engine, attributes_with_not_and_like_and_not_like, default_table).map do |rel|
53
+ if rel.left.name.to_s.ends_with? '__not__'
54
+ rel.left.name = rel.left.name.to_s.sub(/__not__$/, '').to_sym
55
+ negate rel
56
+ elsif rel.left.name.to_s.ends_with? '__like__'
57
+ rel.left.name = rel.left.name.to_s.sub(/__like__$/, '').to_sym
58
+ Arel::Nodes::Matches.new rel.left, rel.right
59
+ elsif rel.left.name.to_s.ends_with? '__not_like__'
60
+ rel.left.name = rel.left.name.to_s.sub(/__not_like__$/, '').to_sym
61
+ Arel::Nodes::DoesNotMatch.new rel.left, rel.right
62
+ else
63
+ rel
64
+ end
65
+ end
66
+ end
67
+ end
68
+ alias_method_chain :build_from_hash, :not_and_like_and_not_like
69
+ end
70
+ # 3.0
71
+ else
72
+ include Everywhere::Util
73
+
74
+ # >= 3.0.13
75
+ if ActiveRecord::PredicateBuilder.method(:build_from_hash).arity == -3
76
+ def build_from_hash_with_not_and_like_and_not_like(attributes, default_table, allow_table_name = true)
10
77
  attributes_with_not_and_like_and_not_like = {}
11
78
  attributes.each do |column, value|
12
79
  # {not: {key: value}}
13
- if column.in?([:not, :like, :not_like])
80
+ if (column == :not) || (column == :like) || (column == :not_like)
14
81
  value.each do |k, v|
15
82
  attributes_with_not_and_like_and_not_like["#{k}__#{column}__"] = v
16
83
  end
@@ -18,7 +85,7 @@ module ActiveRecord
18
85
  attributes_with_not_and_like_and_not_like[column] = value
19
86
  end
20
87
  end
21
- build_from_hash_without_not_and_like_and_not_like(engine, attributes_with_not_and_like_and_not_like, default_table).map do |rel|
88
+ build_from_hash_without_not_and_like_and_not_like(attributes_with_not_and_like_and_not_like, default_table, allow_table_name).map do |rel|
22
89
  if rel.left.name.to_s.ends_with? '__not__'
23
90
  rel.left.name = rel.left.name.to_s.sub(/__not__$/, '').to_sym
24
91
  negate rel
@@ -33,35 +100,33 @@ module ActiveRecord
33
100
  end
34
101
  end
35
102
  end
36
- alias_method_chain :build_from_hash, :not_and_like_and_not_like
37
- end
38
- else
39
- include Everywhere::Util
40
-
41
- def build_from_hash_with_not_and_like_and_not_like(attributes, default_table)
42
- attributes_with_not_and_like_and_not_like = {}
43
- attributes.each do |column, value|
44
- # {not: {key: value}}
45
- if (column == :not) || (column == :like) || (column == :not_like)
46
- value.each do |k, v|
47
- attributes_with_not_and_like_and_not_like["#{k}__#{column}__"] = v
103
+ # < 3.0.13
104
+ else
105
+ def build_from_hash_with_not_and_like_and_not_like(attributes, default_table)
106
+ attributes_with_not_and_like_and_not_like = {}
107
+ attributes.each do |column, value|
108
+ # {not: {key: value}}
109
+ if (column == :not) || (column == :like) || (column == :not_like)
110
+ value.each do |k, v|
111
+ attributes_with_not_and_like_and_not_like["#{k}__#{column}__"] = v
112
+ end
113
+ else
114
+ attributes_with_not_and_like_and_not_like[column] = value
48
115
  end
49
- else
50
- attributes_with_not_and_like_and_not_like[column] = value
51
116
  end
52
- end
53
- build_from_hash_without_not_and_like_and_not_like(attributes_with_not_and_like_and_not_like, default_table).map do |rel|
54
- if rel.left.name.to_s.ends_with? '__not__'
55
- rel.left.name = rel.left.name.to_s.sub(/__not__$/, '').to_sym
56
- negate rel
57
- elsif rel.left.name.to_s.ends_with? '__like__'
58
- rel.left.name = rel.left.name.to_s.sub(/__like__$/, '').to_sym
59
- Arel::Nodes::Matches.new rel.left, rel.right
60
- elsif rel.left.name.to_s.ends_with? '__not_like__'
61
- rel.left.name = rel.left.name.to_s.sub(/__not_like__$/, '').to_sym
62
- Arel::Nodes::DoesNotMatch.new rel.left, rel.right
63
- else
64
- rel
117
+ build_from_hash_without_not_and_like_and_not_like(attributes_with_not_and_like_and_not_like, default_table).map do |rel|
118
+ if rel.left.name.to_s.ends_with? '__not__'
119
+ rel.left.name = rel.left.name.to_s.sub(/__not__$/, '').to_sym
120
+ negate rel
121
+ elsif rel.left.name.to_s.ends_with? '__like__'
122
+ rel.left.name = rel.left.name.to_s.sub(/__like__$/, '').to_sym
123
+ Arel::Nodes::Matches.new rel.left, rel.right
124
+ elsif rel.left.name.to_s.ends_with? '__not_like__'
125
+ rel.left.name = rel.left.name.to_s.sub(/__not_like__$/, '').to_sym
126
+ Arel::Nodes::DoesNotMatch.new rel.left, rel.right
127
+ else
128
+ rel
129
+ end
65
130
  end
66
131
  end
67
132
  end
@@ -6,16 +6,76 @@ module ActiveRecord
6
6
  class << self
7
7
  include Everywhere::Util
8
8
 
9
- def build_from_hash_with_not_and_like_and_not_like(engine, attributes, default_table)
9
+ # >= 3.2.4, >= 3.1.5
10
+ if ActiveRecord::PredicateBuilder.method(:build_from_hash).arity == -4
11
+ def build_from_hash_with_not_and_like_and_not_like(engine, attributes, default_table, allow_table_name = true)
12
+ attributes_with_not_and_like_and_not_like = attributes.map do |column, value|
13
+ # {key: {not: value}}
14
+ if value.is_a?(Hash) && (value.keys.size == 1) && value.keys.first.in?([:not, :like, :not_like])
15
+ ["#{column}__#{value.keys.first}__", value.values.first]
16
+ else
17
+ [column, value]
18
+ end
19
+ end
20
+ build_from_hash_without_not_and_like_and_not_like(engine, attributes_with_not_and_like_and_not_like, default_table, allow_table_name).map do |rel|
21
+ if rel.left.name.to_s.ends_with?('__not__')
22
+ rel.left.name = rel.left.name.to_s.sub(/__not__$/, '').to_sym
23
+ negate rel
24
+ elsif rel.left.name.to_s.ends_with?('__like__')
25
+ rel.left.name = rel.left.name.to_s.sub(/__like__$/, '').to_sym
26
+ Arel::Nodes::Matches.new rel.left, rel.right
27
+ elsif rel.left.name.to_s.ends_with?('__not_like__')
28
+ rel.left.name = rel.left.name.to_s.sub(/__not_like__$/, '').to_sym
29
+ Arel::Nodes::DoesNotMatch.new rel.left, rel.right
30
+ else
31
+ rel
32
+ end
33
+ end
34
+ end
35
+ # < 3.2.4, < 3.1.5, >= 4.0?
36
+ else
37
+ def build_from_hash_with_not_and_like_and_not_like(engine, attributes, default_table)
38
+ attributes_with_not_and_like_and_not_like = attributes.map do |column, value|
39
+ # {key: {not: value}}
40
+ if value.is_a?(Hash) && (value.keys.size == 1) && value.keys.first.in?([:not, :like, :not_like])
41
+ ["#{column}__#{value.keys.first}__", value.values.first]
42
+ else
43
+ [column, value]
44
+ end
45
+ end
46
+ build_from_hash_without_not_and_like_and_not_like(engine, attributes_with_not_and_like_and_not_like, default_table).map do |rel|
47
+ if rel.left.name.to_s.ends_with?('__not__')
48
+ rel.left.name = rel.left.name.to_s.sub(/__not__$/, '').to_sym
49
+ negate rel
50
+ elsif rel.left.name.to_s.ends_with?('__like__')
51
+ rel.left.name = rel.left.name.to_s.sub(/__like__$/, '').to_sym
52
+ Arel::Nodes::Matches.new rel.left, rel.right
53
+ elsif rel.left.name.to_s.ends_with?('__not_like__')
54
+ rel.left.name = rel.left.name.to_s.sub(/__not_like__$/, '').to_sym
55
+ Arel::Nodes::DoesNotMatch.new rel.left, rel.right
56
+ else
57
+ rel
58
+ end
59
+ end
60
+ end
61
+ end
62
+ alias_method_chain :build_from_hash, :not_and_like_and_not_like
63
+ end
64
+ else
65
+ include Everywhere::Util
66
+
67
+ # >= 3.0.13
68
+ if ActiveRecord::PredicateBuilder.method(:build_from_hash).arity == -3
69
+ def build_from_hash_with_not_and_like_and_not_like(attributes, default_table, allow_table_name = true)
10
70
  attributes_with_not_and_like_and_not_like = attributes.map do |column, value|
11
71
  # {key: {not: value}}
12
- if value.is_a?(Hash) && (value.keys.size == 1) && value.keys.first.in?([:not, :like, :not_like])
72
+ if value.is_a?(Hash) && (value.keys.size == 1) && ((value.keys.first == :not) || (value.keys.first == :like) || (value.keys.first == :not_like))
13
73
  ["#{column}__#{value.keys.first}__", value.values.first]
14
74
  else
15
75
  [column, value]
16
76
  end
17
77
  end
18
- build_from_hash_without_not_and_like_and_not_like(engine, attributes_with_not_and_like_and_not_like, default_table).map do |rel|
78
+ build_from_hash_without_not_and_like_and_not_like(attributes_with_not_and_like_and_not_like, default_table, allow_table_name).map do |rel|
19
79
  if rel.left.name.to_s.ends_with?('__not__')
20
80
  rel.left.name = rel.left.name.to_s.sub(/__not__$/, '').to_sym
21
81
  negate rel
@@ -30,32 +90,30 @@ module ActiveRecord
30
90
  end
31
91
  end
32
92
  end
33
- alias_method_chain :build_from_hash, :not_and_like_and_not_like
34
- end
35
- else
36
- include Everywhere::Util
37
-
38
- def build_from_hash_with_not_and_like_and_not_like(attributes, default_table)
39
- attributes_with_not_and_like_and_not_like = attributes.map do |column, value|
40
- # {key: {not: value}}
41
- if value.is_a?(Hash) && (value.keys.size == 1) && ((value.keys.first == :not) || (value.keys.first == :like) || (value.keys.first == :not_like))
42
- ["#{column}__#{value.keys.first}__", value.values.first]
43
- else
44
- [column, value]
93
+ # < 3.0.13
94
+ else
95
+ def build_from_hash_with_not_and_like_and_not_like(attributes, default_table)
96
+ attributes_with_not_and_like_and_not_like = attributes.map do |column, value|
97
+ # {key: {not: value}}
98
+ if value.is_a?(Hash) && (value.keys.size == 1) && ((value.keys.first == :not) || (value.keys.first == :like) || (value.keys.first == :not_like))
99
+ ["#{column}__#{value.keys.first}__", value.values.first]
100
+ else
101
+ [column, value]
102
+ end
45
103
  end
46
- end
47
- build_from_hash_without_not_and_like_and_not_like(attributes_with_not_and_like_and_not_like, default_table).map do |rel|
48
- if rel.left.name.to_s.ends_with?('__not__')
49
- rel.left.name = rel.left.name.to_s.sub(/__not__$/, '').to_sym
50
- negate rel
51
- elsif rel.left.name.to_s.ends_with?('__like__')
52
- rel.left.name = rel.left.name.to_s.sub(/__like__$/, '').to_sym
53
- Arel::Nodes::Matches.new rel.left, rel.right
54
- elsif rel.left.name.to_s.ends_with?('__not_like__')
55
- rel.left.name = rel.left.name.to_s.sub(/__not_like__$/, '').to_sym
56
- Arel::Nodes::DoesNotMatch.new rel.left, rel.right
57
- else
58
- rel
104
+ build_from_hash_without_not_and_like_and_not_like(attributes_with_not_and_like_and_not_like, default_table).map do |rel|
105
+ if rel.left.name.to_s.ends_with?('__not__')
106
+ rel.left.name = rel.left.name.to_s.sub(/__not__$/, '').to_sym
107
+ negate rel
108
+ elsif rel.left.name.to_s.ends_with?('__like__')
109
+ rel.left.name = rel.left.name.to_s.sub(/__like__$/, '').to_sym
110
+ Arel::Nodes::Matches.new rel.left, rel.right
111
+ elsif rel.left.name.to_s.ends_with?('__not_like__')
112
+ rel.left.name = rel.left.name.to_s.sub(/__not_like__$/, '').to_sym
113
+ Arel::Nodes::DoesNotMatch.new rel.left, rel.right
114
+ else
115
+ rel
116
+ end
59
117
  end
60
118
  end
61
119
  end
@@ -1,3 +1,3 @@
1
1
  module Everywhere
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: everywhere
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-25 00:00:00.000000000 Z
12
+ date: 2012-06-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70208330286520 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70208330286520
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: sqlite3
27
- requirement: &70208330286100 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '0'
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *70208330286100
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: activerecord
38
- requirement: &70208330285680 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,7 +53,12 @@ dependencies:
43
53
  version: '0'
44
54
  type: :runtime
45
55
  prerelease: false
46
- version_requirements: *70208330285680
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  description: Hash condition syntax for AR query everywhere!
48
63
  email:
49
64
  - ronnie@dio.jp
@@ -91,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
106
  version: '0'
92
107
  requirements: []
93
108
  rubyforge_project: everywhere
94
- rubygems_version: 1.8.10
109
+ rubygems_version: 1.8.24
95
110
  signing_key:
96
111
  specification_version: 3
97
112
  summary: Hash condition syntax for AR query everywhere!