diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-08-16 14:09:48 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-08-16 14:09:48 -0700 |
commit | bd3ecd761e7b52eabf32efe2f5c4ad722423a623 (patch) | |
tree | 8666102a434cbd1069217808f256a47bf84cdbdf /lib | |
parent | e1155aa922a04e1cce60a660b4b779bfe3d7d7f5 (diff) | |
download | rails-bd3ecd761e7b52eabf32efe2f5c4ad722423a623.tar.gz rails-bd3ecd761e7b52eabf32efe2f5c4ad722423a623.tar.bz2 rails-bd3ecd761e7b52eabf32efe2f5c4ad722423a623.zip |
quoting strings from equality statements, adding to_dot
Diffstat (limited to 'lib')
-rw-r--r-- | lib/arel/tree_manager.rb | 4 | ||||
-rw-r--r-- | lib/arel/visitors/dot.rb | 8 | ||||
-rw-r--r-- | lib/arel/visitors/to_sql.rb | 2 |
3 files changed, 12 insertions, 2 deletions
diff --git a/lib/arel/tree_manager.rb b/lib/arel/tree_manager.rb index 9dd9f27858..d2027bedfa 100644 --- a/lib/arel/tree_manager.rb +++ b/lib/arel/tree_manager.rb @@ -7,6 +7,10 @@ module Arel @engine = engine end + def to_dot + Visitors::Dot.new.accept @head + end + def to_sql viz = Visitors::ToSql.new @engine viz.accept @head diff --git a/lib/arel/visitors/dot.rb b/lib/arel/visitors/dot.rb index 4620920484..4b37927685 100644 --- a/lib/arel/visitors/dot.rb +++ b/lib/arel/visitors/dot.rb @@ -56,6 +56,8 @@ module Arel end alias :visit_Time :visit_String alias :visit_NilClass :visit_String + alias :visit_Arel_SqlLiteral :visit_String + alias :visit_Fixnum :visit_String def visit_Hash o o.each_with_index do |pair, i| @@ -105,13 +107,17 @@ module Arel @node_stack.pop end + def quote string + string.to_s.gsub('"', '\"') + end + def to_dot "digraph \"ARel\" {\nnode [width=0.375,height=0.25,shape=record];\n" + @nodes.map { |node| label = "<f0>#{node.name}" node.fields.each_with_index do |field, i| - label << "|<f#{i + 1}>#{field}" + label << "|<f#{i + 1}>#{quote field}" end "#{node.id} [label=\"#{label}\"];" diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index 5536ba0267..736c0ce77b 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -57,7 +57,7 @@ module Arel end def visit_Arel_Nodes_Equality o - "#{visit o.left} = #{visit o.right}" + "#{visit o.left} = #{quote visit o.right}" end def visit_Arel_Attributes_Attribute o |