From 0d69486b7c4ab347133847589da282945b8b85c6 Mon Sep 17 00:00:00 2001
From: Vipul A M <vipulnsward@gmail.com>
Date: Sun, 31 May 2015 19:56:21 +0530
Subject: Move casted to its own file

---
 lib/arel/nodes/casted.rb | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
 create mode 100644 lib/arel/nodes/casted.rb

(limited to 'lib/arel/nodes')

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
-- 
cgit v1.2.3