diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-11-29 15:17:59 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-11-29 15:17:59 -0800 |
commit | 039947e5ac9c9a2e19282e3548ab7a1f30cbbc3a (patch) | |
tree | 8d9beb8dd6d04f1825d2b67e74c7a880f28ef504 /lib | |
parent | 963ca860d579a507effbe818da0c89bf443f33c9 (diff) | |
download | rails-039947e5ac9c9a2e19282e3548ab7a1f30cbbc3a.tar.gz rails-039947e5ac9c9a2e19282e3548ab7a1f30cbbc3a.tar.bz2 rails-039947e5ac9c9a2e19282e3548ab7a1f30cbbc3a.zip |
updating nodes and depth first visitor
Diffstat (limited to 'lib')
-rw-r--r-- | lib/arel/nodes/delete_statement.rb | 14 | ||||
-rw-r--r-- | lib/arel/nodes/lock.rb | 2 | ||||
-rw-r--r-- | lib/arel/nodes/not.rb | 7 | ||||
-rw-r--r-- | lib/arel/nodes/on.rb | 7 | ||||
-rw-r--r-- | lib/arel/nodes/table_alias.rb | 10 | ||||
-rw-r--r-- | lib/arel/nodes/unqualified_column.rb | 13 | ||||
-rw-r--r-- | lib/arel/nodes/values.rb | 10 | ||||
-rw-r--r-- | lib/arel/visitors/depth_first.rb | 77 |
8 files changed, 89 insertions, 51 deletions
diff --git a/lib/arel/nodes/delete_statement.rb b/lib/arel/nodes/delete_statement.rb index 610d69e460..3bac8225ec 100644 --- a/lib/arel/nodes/delete_statement.rb +++ b/lib/arel/nodes/delete_statement.rb @@ -1,16 +1,18 @@ module Arel module Nodes - class DeleteStatement - attr_accessor :relation, :wheres + class DeleteStatement < Arel::Nodes::Binary + alias :relation :left + alias :relation= :left= + alias :wheres :right + alias :wheres= :right= - def initialize - @from = nil - @wheres = [] + def initialize relation = nil, wheres = [] + super end def initialize_copy other super - @wheres = @wheres.clone + @right = @right.clone end end end diff --git a/lib/arel/nodes/lock.rb b/lib/arel/nodes/lock.rb index 3c7a72273f..e5fb258e26 100644 --- a/lib/arel/nodes/lock.rb +++ b/lib/arel/nodes/lock.rb @@ -1,6 +1,6 @@ module Arel module Nodes - class Lock + class Lock < Arel::Nodes::Node end end end diff --git a/lib/arel/nodes/not.rb b/lib/arel/nodes/not.rb index d463ae9d08..de138435bb 100644 --- a/lib/arel/nodes/not.rb +++ b/lib/arel/nodes/not.rb @@ -1,11 +1,6 @@ module Arel module Nodes - class Not < Arel::Nodes::Node - attr_reader :expr - - def initialize expr - @expr = expr - end + class Not < Arel::Nodes::Unary end end end diff --git a/lib/arel/nodes/on.rb b/lib/arel/nodes/on.rb index 4cc76b70db..953d64f9f1 100644 --- a/lib/arel/nodes/on.rb +++ b/lib/arel/nodes/on.rb @@ -1,11 +1,6 @@ module Arel module Nodes - class On - attr_accessor :expr - - def initialize expr - @expr = expr - end + class On < Arel::Nodes::Unary end end end diff --git a/lib/arel/nodes/table_alias.rb b/lib/arel/nodes/table_alias.rb index 60da7b19f3..723b025883 100644 --- a/lib/arel/nodes/table_alias.rb +++ b/lib/arel/nodes/table_alias.rb @@ -1,14 +1,10 @@ module Arel module Nodes - class TableAlias - attr_reader :name, :relation + class TableAlias < Arel::Nodes::Binary + alias :name :left + alias :relation :right alias :table_alias :name - def initialize name, relation - @name = name - @relation = relation - end - def [] name Attribute.new self, name end diff --git a/lib/arel/nodes/unqualified_column.rb b/lib/arel/nodes/unqualified_column.rb index 9882cb08e2..f7ba653c11 100644 --- a/lib/arel/nodes/unqualified_column.rb +++ b/lib/arel/nodes/unqualified_column.rb @@ -1,18 +1,15 @@ module Arel module Nodes - class UnqualifiedColumn - attr_accessor :attribute - - def initialize attribute - @attribute = attribute - end + class UnqualifiedColumn < Arel::Nodes::Unary + alias :attribute :expr + alias :attribute= :expr= def column - @attribute.column + @expr.column end def name - @attribute.name + @expr.name end end end diff --git a/lib/arel/nodes/values.rb b/lib/arel/nodes/values.rb index 4c7ca76360..814e843dab 100644 --- a/lib/arel/nodes/values.rb +++ b/lib/arel/nodes/values.rb @@ -1,11 +1,13 @@ module Arel module Nodes - class Values - attr_accessor :expressions, :columns + class Values < Arel::Nodes::Binary + alias :expressions :left + alias :expressions= :left= + alias :columns :right + alias :columns= :right= def initialize exprs, columns = [] - @expressions = exprs - @columns = columns + super end end end diff --git a/lib/arel/visitors/depth_first.rb b/lib/arel/visitors/depth_first.rb index d6d3984ce2..3d34ff139e 100644 --- a/lib/arel/visitors/depth_first.rb +++ b/lib/arel/visitors/depth_first.rb @@ -7,14 +7,55 @@ module Arel private + def unary o + visit o.expr + @block.call o + end + alias :visit_Arel_Nodes_Group :unary + alias :visit_Arel_Nodes_Grouping :unary + alias :visit_Arel_Nodes_Having :unary + alias :visit_Arel_Nodes_Not :unary + alias :visit_Arel_Nodes_Offset :unary + alias :visit_Arel_Nodes_On :unary + alias :visit_Arel_Nodes_UnqualifiedColumn :unary + + def function o + visit o.expressions + visit o.alias + @block.call o + end + alias :visit_Arel_Nodes_Avg :function + alias :visit_Arel_Nodes_Exists :function + alias :visit_Arel_Nodes_Max :function + alias :visit_Arel_Nodes_Min :function + alias :visit_Arel_Nodes_Sum :function + + def visit_Arel_Nodes_Count o + visit o.expressions + visit o.alias + visit o.distinct + @block.call o + end + + def join o + visit o.left + visit o.right + visit o.constraint + @block.call o + end + alias :visit_Arel_Nodes_InnerJoin :join + alias :visit_Arel_Nodes_OuterJoin :join + def binary o visit o.left visit o.right @block.call o end alias :visit_Arel_Nodes_And :binary + alias :visit_Arel_Nodes_As :binary alias :visit_Arel_Nodes_Assignment :binary alias :visit_Arel_Nodes_Between :binary + alias :visit_Arel_Nodes_DeleteStatement :binary alias :visit_Arel_Nodes_DoesNotMatch :binary alias :visit_Arel_Nodes_Equality :binary alias :visit_Arel_Nodes_GreaterThan :binary @@ -26,6 +67,10 @@ module Arel alias :visit_Arel_Nodes_NotEqual :binary alias :visit_Arel_Nodes_NotIn :binary alias :visit_Arel_Nodes_Or :binary + alias :visit_Arel_Nodes_Ordering :binary + alias :visit_Arel_Nodes_StringJoin :binary + alias :visit_Arel_Nodes_TableAlias :binary + alias :visit_Arel_Nodes_Values :binary def visit_Arel_Attribute o visit o.relation @@ -38,6 +83,7 @@ module Arel alias :visit_Arel_Attributes_Time :visit_Arel_Attribute alias :visit_Arel_Attributes_Boolean :visit_Arel_Attribute alias :visit_Arel_Attributes_Attribute :visit_Arel_Attribute + alias :visit_Arel_Attributes_Decimal :visit_Arel_Attribute def visit_Arel_Table o visit o.name @@ -47,19 +93,24 @@ module Arel def terminal o @block.call o end - alias :visit_Arel_Nodes_SqlLiteral :terminal - alias :visit_Arel_SqlLiteral :terminal - alias :visit_BigDecimal :terminal - alias :visit_Date :terminal - alias :visit_DateTime :terminal - alias :visit_FalseClass :terminal - alias :visit_Fixnum :terminal - alias :visit_Float :terminal - alias :visit_NilClass :terminal - alias :visit_String :terminal - alias :visit_Symbol :terminal - alias :visit_Time :terminal - alias :visit_TrueClass :terminal + alias :visit_ActiveSupport_Multibyte_Chars :terminal + alias :visit_ActiveSupport_StringInquirer :terminal + alias :visit_Arel_Nodes_Lock :terminal + alias :visit_Arel_Nodes_SqlLiteral :terminal + alias :visit_Arel_SqlLiteral :terminal + alias :visit_BigDecimal :terminal + alias :visit_Bignum :terminal + alias :visit_Class :terminal + alias :visit_Date :terminal + alias :visit_DateTime :terminal + alias :visit_FalseClass :terminal + alias :visit_Fixnum :terminal + alias :visit_Float :terminal + alias :visit_NilClass :terminal + alias :visit_String :terminal + alias :visit_Symbol :terminal + alias :visit_Time :terminal + alias :visit_TrueClass :terminal def visit_Arel_Nodes_InsertStatement o visit o.relation |