123456789_123456789_123456789_123456789_123456789_

Class: Arel::Visitors::Visitor

Do not use. This class is for internal use only.
Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Inherits: Object
Defined in: activerecord/lib/arel/visitors/visitor.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.newVisitor

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/visitor.rb', line 6

def initialize
  @dispatch = get_dispatch_cache
end

Class Method Details

.dispatch_cache (private)

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/visitor.rb', line 17

def self.dispatch_cache
  @dispatch_cache ||= Hash.new do |hash, klass|
    hash[klass] = :"visit_#{(klass.name || "").gsub("::", "_")}"
  end.compare_by_identity
end

Instance Attribute Details

#dispatch (readonly, private)

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/visitor.rb', line 15

attr_reader :dispatch

Instance Method Details

#accept(object, collector = nil)

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/visitor.rb', line 10

def accept(object, collector = nil)
  visit object, collector
end

#get_dispatch_cache (private)

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/visitor.rb', line 23

def get_dispatch_cache
  self.class.dispatch_cache
end

#visit(object, collector = nil) (private)

[ GitHub ]

  
# File 'activerecord/lib/arel/visitors/visitor.rb', line 27

def visit(object, collector = nil)
  dispatch_method = dispatch[object.class]
  if collector
    send dispatch_method, object, collector
  else
    send dispatch_method, object
  end
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