diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-08-13 08:11:08 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-08-13 08:11:08 -0700 |
commit | 38b10d5ea1411e4adcbb190cc6a38c9529b8998c (patch) | |
tree | 936f7b03d8978847407a0cea5c8a2c12dbb3b6ea /lib/arel/visitors | |
parent | e573a9ea468d748cf0ebd1a70521c1589efda23e (diff) | |
download | rails-38b10d5ea1411e4adcbb190cc6a38c9529b8998c.tar.gz rails-38b10d5ea1411e4adcbb190cc6a38c9529b8998c.tar.bz2 rails-38b10d5ea1411e4adcbb190cc6a38c9529b8998c.zip |
project works with strings
Diffstat (limited to 'lib/arel/visitors')
-rw-r--r-- | lib/arel/visitors/to_sql.rb | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index 44a585698f..53ae6e0860 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -22,8 +22,8 @@ module Arel def visit_Arel_Nodes_SelectCore o [ "SELECT #{o.projections.map { |x| visit x }.join ', '}", - "FROM #{o.froms.map { |x| visit x }.join ', ' }", - ("WHERE #{o.wheres.map { |x| visit x }.join ' AND ' }" unless o.wheres.blank?) + ("FROM #{o.froms.map { |x| visit x }.join ', ' }" unless o.froms.empty?), + ("WHERE #{o.wheres.map { |x| visit x }.join ' AND ' }" unless o.wheres.empty?) ].compact.join ' ' end @@ -40,9 +40,20 @@ module Arel end def visit_Fixnum o; o end + alias :visit_String :visit_Fixnum + alias :visit_Arel_Nodes_SqlLiteral :visit_Fixnum + alias :visit_Arel_SqlLiteral :visit_Fixnum # This is deprecated + DISPATCH = {} def visit object - send :"visit_#{object.class.name.gsub('::', '_')}", object + send DISPATCH[object.class], object + end + + private_instance_methods(false).each do |method| + method = method.to_s + next unless method =~ /^visit_(.*)$/ + const = $1.split('_').inject(Object) { |m,s| m.const_get s } + DISPATCH[const] = method end def quote_table_name name |