mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
b57a11cb8a
visitors are not shared among threads, so any mutations to the cache should be OK. The cache is also pre-populated on construction, but we should pull that out so we can share the cache among visitors in the future.
25 lines
691 B
Ruby
25 lines
691 B
Ruby
require 'arel/visitors/visitor'
|
|
|
|
module Arel
|
|
module Visitors
|
|
class Reduce < Arel::Visitors::Visitor
|
|
def accept object, collector
|
|
visit object, collector
|
|
end
|
|
|
|
private
|
|
|
|
def visit object, collector
|
|
send dispatch[object.class.name], object, collector
|
|
rescue NoMethodError => e
|
|
raise e if respond_to?(dispatch[object.class.name], true)
|
|
superklass = object.class.ancestors.find { |klass|
|
|
respond_to?(dispatch[klass.name], true)
|
|
}
|
|
raise(TypeError, "Cannot visit #{object.class}") unless superklass
|
|
dispatch[object.class.name] = dispatch[superklass.name]
|
|
retry
|
|
end
|
|
end
|
|
end
|
|
end
|