aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/predications.rb
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2014-10-27 16:58:05 -0600
committerSean Griffin <sean@thoughtbot.com>2014-10-27 16:58:05 -0600
commit7db0e4accff919f0a7aea875fbc8d9f5696ecb69 (patch)
treea9de116ade93877d677c5e77c04d6c137ce9a3fd /lib/arel/predications.rb
parentafd98824eb22b67b1f74edd5ea19e4a19a9da981 (diff)
downloadrails-7db0e4accff919f0a7aea875fbc8d9f5696ecb69.tar.gz
rails-7db0e4accff919f0a7aea875fbc8d9f5696ecb69.tar.bz2
rails-7db0e4accff919f0a7aea875fbc8d9f5696ecb69.zip
Dry up building quoted nodes in predication
Given that we are going to remove casting from Arel in the near future, having a single place nodes in predications will help.
Diffstat (limited to 'lib/arel/predications.rb')
-rw-r--r--lib/arel/predications.rb38
1 files changed, 23 insertions, 15 deletions
diff --git a/lib/arel/predications.rb b/lib/arel/predications.rb
index a0b6728943..f11f8dc86d 100644
--- a/lib/arel/predications.rb
+++ b/lib/arel/predications.rb
@@ -1,7 +1,7 @@
module Arel
module Predications
def not_eq other
- Nodes::NotEqual.new self, Nodes.build_quoted(other, self)
+ Nodes::NotEqual.new self, quoted_node(other)
end
def not_eq_any others
@@ -13,7 +13,7 @@ module Arel
end
def eq other
- Nodes::Equality.new self, Nodes.build_quoted(other, self)
+ Nodes::Equality.new self, quoted_node(other)
end
def eq_any others
@@ -21,7 +21,7 @@ module Arel
end
def eq_all others
- grouping_all :eq, others.map { |x| Nodes.build_quoted(x, self) }
+ grouping_all :eq, quoted_array(others)
end
def between other
@@ -38,8 +38,8 @@ module Arel
elsif other.exclude_end?
gteq(other.begin).and(lt(other.end))
else
- left = Nodes.build_quoted(other.begin, self)
- right = Nodes.build_quoted(other.end, self)
+ left = quoted_node(other.begin)
+ right = quoted_node(other.end)
Nodes::Between.new(self, left.and(right))
end
end
@@ -56,9 +56,9 @@ Passing a range to `#in` is deprecated. Call `#between`, instead.
end
between(other)
when Array
- Nodes::In.new self, other.map { |x| Nodes.build_quoted(x, self) }
+ Nodes::In.new self, quoted_array(other)
else
- Nodes::In.new self, Nodes.build_quoted(other, self)
+ Nodes::In.new self, quoted_node(other)
end
end
@@ -104,9 +104,9 @@ Passing a range to `#not_in` is deprecated. Call `#not_between`, instead.
end
not_between(other)
when Array
- Nodes::NotIn.new self, other.map { |x| Nodes.build_quoted(x, self) }
+ Nodes::NotIn.new self, quoted_array(other)
else
- Nodes::NotIn.new self, Nodes.build_quoted(other, self)
+ Nodes::NotIn.new self, quoted_node(other)
end
end
@@ -119,7 +119,7 @@ Passing a range to `#not_in` is deprecated. Call `#not_between`, instead.
end
def matches other, escape = nil
- Nodes::Matches.new self, Nodes.build_quoted(other, self), escape
+ Nodes::Matches.new self, quoted_node(other), escape
end
def matches_any others, escape = nil
@@ -131,7 +131,7 @@ Passing a range to `#not_in` is deprecated. Call `#not_between`, instead.
end
def does_not_match other, escape = nil
- Nodes::DoesNotMatch.new self, Nodes.build_quoted(other, self), escape
+ Nodes::DoesNotMatch.new self, quoted_node(other), escape
end
def does_not_match_any others, escape = nil
@@ -143,7 +143,7 @@ Passing a range to `#not_in` is deprecated. Call `#not_between`, instead.
end
def gteq right
- Nodes::GreaterThanOrEqual.new self, Nodes.build_quoted(right, self)
+ Nodes::GreaterThanOrEqual.new self, quoted_node(right)
end
def gteq_any others
@@ -155,7 +155,7 @@ Passing a range to `#not_in` is deprecated. Call `#not_between`, instead.
end
def gt right
- Nodes::GreaterThan.new self, Nodes.build_quoted(right, self)
+ Nodes::GreaterThan.new self, quoted_node(right)
end
def gt_any others
@@ -167,7 +167,7 @@ Passing a range to `#not_in` is deprecated. Call `#not_between`, instead.
end
def lt right
- Nodes::LessThan.new self, Nodes.build_quoted(right, self)
+ Nodes::LessThan.new self, quoted_node(right)
end
def lt_any others
@@ -179,7 +179,7 @@ Passing a range to `#not_in` is deprecated. Call `#not_between`, instead.
end
def lteq right
- Nodes::LessThanOrEqual.new self, Nodes.build_quoted(right, self)
+ Nodes::LessThanOrEqual.new self, quoted_node(right)
end
def lteq_any others
@@ -203,5 +203,13 @@ Passing a range to `#not_in` is deprecated. Call `#not_between`, instead.
nodes = others.map {|expr| send(method_id, expr, *extras)}
Nodes::Grouping.new Nodes::And.new(nodes)
end
+
+ def quoted_node(other)
+ Nodes.build_quoted(other, self)
+ end
+
+ def quoted_array(others)
+ others.map { |v| quoted_node(v) }
+ end
end
end