diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-04-08 12:03:52 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-04-08 12:03:52 -0700 |
commit | 05b5bb12270b32e094c1c879273e0978dabe5b3b (patch) | |
tree | 24a09e4abc6bdb10e62626577e3c024c10707a19 /lib/arel/visitors | |
parent | df52f7ca2ffe1dd4fb8e65db352c7bcaacfea1a5 (diff) | |
download | rails-05b5bb12270b32e094c1c879273e0978dabe5b3b.tar.gz rails-05b5bb12270b32e094c1c879273e0978dabe5b3b.tar.bz2 rails-05b5bb12270b32e094c1c879273e0978dabe5b3b.zip |
bind visitor working with collector object
Diffstat (limited to 'lib/arel/visitors')
-rw-r--r-- | lib/arel/visitors/bind_visitor.rb | 12 | ||||
-rw-r--r-- | lib/arel/visitors/to_sql.rb | 5 | ||||
-rw-r--r-- | lib/arel/visitors/visitor.rb | 8 |
3 files changed, 14 insertions, 11 deletions
diff --git a/lib/arel/visitors/bind_visitor.rb b/lib/arel/visitors/bind_visitor.rb index 5cb251ffde..c316c8d702 100644 --- a/lib/arel/visitors/bind_visitor.rb +++ b/lib/arel/visitors/bind_visitor.rb @@ -6,24 +6,26 @@ module Arel super end - def accept node, &block + def accept node, collector, &block @block = block if block_given? super end private - def visit_Arel_Nodes_Assignment o + def visit_Arel_Nodes_Assignment o, collector if o.right.is_a? Arel::Nodes::BindParam - "#{visit o.left} = #{visit o.right}" + collector = visit o.left, collector + collector << " = " + visit o.right, collector else super end end - def visit_Arel_Nodes_BindParam o + def visit_Arel_Nodes_BindParam o, collector if @block - @block.call + @block.call(collector) else super end diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index 0c2e649995..8c90fd76af 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -533,8 +533,9 @@ module Arel "#{visit o.left} AS #{visit o.right}" end - def visit_Arel_Nodes_UnqualifiedColumn o - "#{quote_column_name o.name}" + def visit_Arel_Nodes_UnqualifiedColumn o, collector + collector << "#{quote_column_name o.name}" + collector end def visit_Arel_Attributes_Attribute o diff --git a/lib/arel/visitors/visitor.rb b/lib/arel/visitors/visitor.rb index 0540445088..2d4b472ea3 100644 --- a/lib/arel/visitors/visitor.rb +++ b/lib/arel/visitors/visitor.rb @@ -1,8 +1,8 @@ module Arel module Visitors class Visitor - def accept object - visit object + def accept object, collector + visit object, collector end private @@ -18,8 +18,8 @@ module Arel DISPATCH[self.class] end - def visit object - send dispatch[object.class], object + def visit object, collector + send dispatch[object.class], object, collector rescue NoMethodError => e raise e if respond_to?(dispatch[object.class], true) superklass = object.class.ancestors.find { |klass| |