diff options
-rw-r--r-- | lib/arel/visitors/depth_first.rb | 6 | ||||
-rw-r--r-- | lib/arel/visitors/visitor.rb | 21 |
2 files changed, 21 insertions, 6 deletions
diff --git a/lib/arel/visitors/depth_first.rb b/lib/arel/visitors/depth_first.rb index a434f404c7..d7d85cfcc6 100644 --- a/lib/arel/visitors/depth_first.rb +++ b/lib/arel/visitors/depth_first.rb @@ -173,6 +173,12 @@ module Arel def visit_Hash o o.each { |k,v| visit(k); visit(v) } end + + DISPATCH = dispatch_cache + + def get_dispatch_cache + DISPATCH + end end end end diff --git a/lib/arel/visitors/visitor.rb b/lib/arel/visitors/visitor.rb index 146ae216f6..2152da9f05 100644 --- a/lib/arel/visitors/visitor.rb +++ b/lib/arel/visitors/visitor.rb @@ -2,7 +2,17 @@ module Arel module Visitors class Visitor def initialize - @dispatch = Hash.new do |hash, class_name| + @dispatch = get_dispatch_cache + end + + def accept object + visit object + end + + private + + def self.dispatch_cache + dispatch = Hash.new do |hash, class_name| hash[class_name] = "visit_#{(class_name || '').gsub('::', '_')}" end @@ -10,16 +20,15 @@ module Arel # instance, but we can do that later. self.class.private_instance_methods.sort.each do |name| next unless name =~ /^visit_(.*)$/ - @dispatch[$1.gsub('_', '::')] = name + dispatch[$1.gsub('_', '::')] = name end + dispatch end - def accept object - visit object + def get_dispatch_cache + self.class.dispatch_cache end - private - def dispatch @dispatch end |