diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/arel/math.rb | 24 | ||||
-rw-r--r-- | lib/arel/nodes.rb | 1 | ||||
-rw-r--r-- | lib/arel/nodes/infix_operation.rb | 30 | ||||
-rw-r--r-- | lib/arel/nodes/unary_operation.rb | 25 | ||||
-rw-r--r-- | lib/arel/visitors/to_sql.rb | 5 |
5 files changed, 85 insertions, 0 deletions
diff --git a/lib/arel/math.rb b/lib/arel/math.rb index f3dbc7bc49..04cae84598 100644 --- a/lib/arel/math.rb +++ b/lib/arel/math.rb @@ -15,5 +15,29 @@ module Arel def /(other) Arel::Nodes::Division.new(self, other) end + + def &(other) + Arel::Nodes::Grouping.new(Arel::Nodes::BitwiseAnd.new(self, other)) + end + + def |(other) + Arel::Nodes::Grouping.new(Arel::Nodes::BitwiseOr.new(self, other)) + end + + def ^(other) + Arel::Nodes::Grouping.new(Arel::Nodes::BitwiseXor.new(self, other)) + end + + def <<(other) + Arel::Nodes::Grouping.new(Arel::Nodes::BitwiseShiftLeft.new(self, other)) + end + + def >>(other) + Arel::Nodes::Grouping.new(Arel::Nodes::BitwiseShiftRight.new(self, other)) + end + + def ~@ + Arel::Nodes::BitwiseNot.new(self) + end end end diff --git a/lib/arel/nodes.rb b/lib/arel/nodes.rb index 89f0f563ac..ff27bb9aa8 100644 --- a/lib/arel/nodes.rb +++ b/lib/arel/nodes.rb @@ -28,6 +28,7 @@ require 'arel/nodes/join_source' require 'arel/nodes/delete_statement' require 'arel/nodes/table_alias' require 'arel/nodes/infix_operation' +require 'arel/nodes/unary_operation' require 'arel/nodes/over' require 'arel/nodes/matches' require 'arel/nodes/regexp' diff --git a/lib/arel/nodes/infix_operation.rb b/lib/arel/nodes/infix_operation.rb index a3f04da6fa..55ac715f73 100644 --- a/lib/arel/nodes/infix_operation.rb +++ b/lib/arel/nodes/infix_operation.rb @@ -45,5 +45,35 @@ module Arel super('||', left, right) end end + + class BitwiseAnd < InfixOperation + def initialize left, right + super(:&, left, right) + end + end + + class BitwiseOr < InfixOperation + def initialize left, right + super(:|, left, right) + end + end + + class BitwiseXor < InfixOperation + def initialize left, right + super(:^, left, right) + end + end + + class BitwiseShiftLeft < InfixOperation + def initialize left, right + super(:<<, left, right) + end + end + + class BitwiseShiftRight < InfixOperation + def initialize left, right + super(:>>, left, right) + end + end end end diff --git a/lib/arel/nodes/unary_operation.rb b/lib/arel/nodes/unary_operation.rb new file mode 100644 index 0000000000..1636c01279 --- /dev/null +++ b/lib/arel/nodes/unary_operation.rb @@ -0,0 +1,25 @@ +module Arel + module Nodes + + class UnaryOperation < Unary + include Arel::Expressions + include Arel::Predications + include Arel::OrderPredications + include Arel::AliasPredication + include Arel::Math + + attr_reader :operator + + def initialize operator, operand + super(operand) + @operator = operator + end + end + + class BitwiseNot < UnaryOperation + def initialize operand + super(:~, operand) + end + end + end +end
\ No newline at end of file diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index 598bf2d984..80bea56ce6 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -801,6 +801,11 @@ module Arel alias :visit_Arel_Nodes_Multiplication :visit_Arel_Nodes_InfixOperation alias :visit_Arel_Nodes_Division :visit_Arel_Nodes_InfixOperation + def visit_Arel_Nodes_UnaryOperation o, collector + collector << " #{o.operator} " + visit o.expr, collector + end + def visit_Array o, collector inject_join o, collector, ", " end |