diff options
Diffstat (limited to 'lib/arel/visitors/visitor.rb')
-rw-r--r-- | lib/arel/visitors/visitor.rb | 21 |
1 files changed, 15 insertions, 6 deletions
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 |