Permalink
Browse files

adding a base class visitor

  • Loading branch information...
1 parent aca9b5b commit 6cd43f5044e169c5044cd337f7f101c9ee18712d @tenderlove tenderlove committed Oct 19, 2010
Showing with 22 additions and 10 deletions.
  1. +1 −0 lib/arel/visitors.rb
  2. +2 −10 lib/arel/visitors/to_sql.rb
  3. +19 −0 lib/arel/visitors/visitor.rb
View
@@ -1,3 +1,4 @@
+require 'arel/visitors/visitor'
require 'arel/visitors/to_sql'
require 'arel/visitors/postgresql'
require 'arel/visitors/mysql'
@@ -3,7 +3,7 @@
module Arel
module Visitors
- class ToSql
+ class ToSql < Arel::Visitors::Visitor
def initialize engine
@engine = engine
@connection = nil
@@ -16,7 +16,7 @@ def accept object
@last_column = nil
@engine.connection_pool.with_connection do |conn|
@connection = conn
- visit object
+ super
end
end
@@ -277,14 +277,6 @@ def visit_String o; quote(o, @last_column) end
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
@@ -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

0 comments on commit 6cd43f5

Please sign in to comment.