diff options
-rw-r--r-- | lib/arel/collectors/plain_string.rb | 18 | ||||
-rw-r--r-- | lib/arel/collectors/sql_string.rb | 17 | ||||
-rw-r--r-- | lib/arel/tree_manager.rb | 4 | ||||
-rw-r--r-- | lib/arel/visitors/dot.rb | 4 | ||||
-rw-r--r-- | test/visitors/test_dot.rb | 8 |
5 files changed, 30 insertions, 21 deletions
diff --git a/lib/arel/collectors/plain_string.rb b/lib/arel/collectors/plain_string.rb new file mode 100644 index 0000000000..2505bc376e --- /dev/null +++ b/lib/arel/collectors/plain_string.rb @@ -0,0 +1,18 @@ +module Arel + module Collectors + class PlainString + def initialize + @str = '' + end + + def value + @str + end + + def << str + @str << str + self + end + end + end +end diff --git a/lib/arel/collectors/sql_string.rb b/lib/arel/collectors/sql_string.rb index 45001bb507..8ca89ca7bd 100644 --- a/lib/arel/collectors/sql_string.rb +++ b/lib/arel/collectors/sql_string.rb @@ -1,21 +1,10 @@ # encoding: utf-8 +require 'arel/collectors/plain_string' + module Arel module Collectors - class SQLString - def initialize - @str = '' - end - - def value - @str - end - - def << str - @str << str - self - end - + class SQLString < PlainString def add_bind bind self << bind.to_s self diff --git a/lib/arel/tree_manager.rb b/lib/arel/tree_manager.rb index 87887800d0..8bff97af78 100644 --- a/lib/arel/tree_manager.rb +++ b/lib/arel/tree_manager.rb @@ -15,7 +15,9 @@ module Arel end def to_dot - Visitors::Dot.new.accept @ast + collector = Arel::Collectors::PlainString.new + collector = Visitors::Dot.new.accept @ast, collector + collector.value end def visitor diff --git a/lib/arel/visitors/dot.rb b/lib/arel/visitors/dot.rb index ba35223ac9..d96cf7a6a0 100644 --- a/lib/arel/visitors/dot.rb +++ b/lib/arel/visitors/dot.rb @@ -22,9 +22,9 @@ module Arel @seen = {} end - def accept object + def accept object, collector visit object - to_dot + collector << to_dot end private diff --git a/test/visitors/test_dot.rb b/test/visitors/test_dot.rb index ee7fc7886c..7763350f5c 100644 --- a/test/visitors/test_dot.rb +++ b/test/visitors/test_dot.rb @@ -17,13 +17,13 @@ module Arel ].each do |klass| define_method("test_#{klass.name.gsub('::', '_')}") do op = klass.new(:a, "z") - @visitor.accept op + @visitor.accept op, Collectors::PlainString.new end end def test_named_function func = Nodes::NamedFunction.new 'omg', 'omg' - @visitor.accept func + @visitor.accept func, Collectors::PlainString.new end # unary ops @@ -41,7 +41,7 @@ module Arel ].each do |klass| define_method("test_#{klass.name.gsub('::', '_')}") do op = klass.new(:a) - @visitor.accept op + @visitor.accept op, Collectors::PlainString.new end end @@ -68,7 +68,7 @@ module Arel ].each do |klass| define_method("test_#{klass.name.gsub('::', '_')}") do binary = klass.new(:a, :b) - @visitor.accept binary + @visitor.accept binary, Collectors::PlainString.new end end end |