class Arel::Visitors::Visitor
Public Class Methods
new()
click to toggle source
# File lib/arel/visitors/visitor.rb, line 4 def initialize @dispatch = get_dispatch_cache end
Private Class Methods
dispatch_cache()
click to toggle source
# File lib/arel/visitors/visitor.rb, line 14 def self.dispatch_cache Hash.new do |hash, klass| hash[klass] = "visit_#{(klass.name || '').gsub('::', '_')}" end end
Public Instance Methods
accept(object)
click to toggle source
# File lib/arel/visitors/visitor.rb, line 8 def accept object visit object end
Private Instance Methods
dispatch()
click to toggle source
# File lib/arel/visitors/visitor.rb, line 24 def dispatch @dispatch end
get_dispatch_cache()
click to toggle source
# File lib/arel/visitors/visitor.rb, line 20 def get_dispatch_cache self.class.dispatch_cache end
visit(object)
click to toggle source
# File lib/arel/visitors/visitor.rb, line 28 def visit object dispatch_method = dispatch[object.class] send dispatch_method, object rescue NoMethodError => e raise e if respond_to?(dispatch_method, true) superklass = object.class.ancestors.find { |klass| respond_to?(dispatch[klass], true) } raise(TypeError, "Cannot visit #{object.class}") unless superklass dispatch[object.class] = dispatch[superklass] retry end