diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/arel/visitors.rb | 1 | ||||
-rw-r--r-- | lib/arel/visitors/to_sql.rb | 12 | ||||
-rw-r--r-- | lib/arel/visitors/visitor.rb | 19 |
3 files changed, 22 insertions, 10 deletions
diff --git a/lib/arel/visitors.rb b/lib/arel/visitors.rb index fc585c39bb..01c6647039 100644 --- a/lib/arel/visitors.rb +++ b/lib/arel/visitors.rb @@ -1,3 +1,4 @@ +require 'arel/visitors/visitor' require 'arel/visitors/to_sql' require 'arel/visitors/postgresql' require 'arel/visitors/mysql' diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index 17779b4037..e68890004a 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -3,7 +3,7 @@ require 'date' module Arel module Visitors - class ToSql + class ToSql < Arel::Visitors::Visitor def initialize engine @engine = engine @connection = nil @@ -16,7 +16,7 @@ module Arel @last_column = nil @engine.connection_pool.with_connection do |conn| @connection = conn - visit object + super end end @@ -277,14 +277,6 @@ module Arel alias :visit_Time :visit_String alias :visit_TrueClass :visit_String - DISPATCH = Hash.new do |hash, klass| - hash[klass] = "visit_#{klass.name.gsub('::', '_')}" - end - - def visit object - send DISPATCH[object.class], object - end - def quote value, column = nil @connection.quote value, column end diff --git a/lib/arel/visitors/visitor.rb b/lib/arel/visitors/visitor.rb new file mode 100644 index 0000000000..510d50399b --- /dev/null +++ b/lib/arel/visitors/visitor.rb @@ -0,0 +1,19 @@ +module Arel + module Visitors + class Visitor + def accept object + visit object + end + + private + + DISPATCH = Hash.new do |hash, klass| + hash[klass] = "visit_#{klass.name.gsub('::', '_')}" + end + + def visit object + send DISPATCH[object.class], object + end + end + end +end |