aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/nodes/casted.rb
diff options
context:
space:
mode:
authorVipul A M <vipulnsward@gmail.com>2015-05-31 19:56:21 +0530
committerVipul A M <vipulnsward@gmail.com>2015-05-31 19:56:21 +0530
commit0d69486b7c4ab347133847589da282945b8b85c6 (patch)
tree41301b2a4805e2b9a7cb4f35760ed0fce8f25fb3 /lib/arel/nodes/casted.rb
parentc7ca1568013d244b9c61147b20b4424d741e91ac (diff)
downloadrails-0d69486b7c4ab347133847589da282945b8b85c6.tar.gz
rails-0d69486b7c4ab347133847589da282945b8b85c6.tar.bz2
rails-0d69486b7c4ab347133847589da282945b8b85c6.zip
Move casted to its own file
Diffstat (limited to 'lib/arel/nodes/casted.rb')
-rw-r--r--lib/arel/nodes/casted.rb40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/arel/nodes/casted.rb b/lib/arel/nodes/casted.rb
new file mode 100644
index 0000000000..9fa02955ef
--- /dev/null
+++ b/lib/arel/nodes/casted.rb
@@ -0,0 +1,40 @@
+module Arel
+ module Nodes
+ class Casted < Arel::Nodes::Node # :nodoc:
+ attr_reader :val, :attribute
+ def initialize val, attribute
+ @val = val
+ @attribute = attribute
+ super()
+ end
+
+ def nil?; @val.nil?; end
+
+ def eql? other
+ self.class == other.class &&
+ self.val == other.val &&
+ self.attribute == other.attribute
+ end
+ alias :== :eql?
+ end
+
+ class Quoted < Arel::Nodes::Unary # :nodoc:
+ alias :val :value
+ def nil?; val.nil?; end
+ end
+
+ def self.build_quoted other, attribute = nil
+ case other
+ when Arel::Nodes::Node, Arel::Attributes::Attribute, Arel::Table, Arel::Nodes::BindParam, Arel::SelectManager, Arel::Nodes::Quoted
+ other
+ else
+ case attribute
+ when Arel::Attributes::Attribute
+ Casted.new other, attribute
+ else
+ Quoted.new other
+ end
+ end
+ end
+ end
+end