aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-06-27 09:11:47 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2011-06-27 09:11:47 -0700
commit0c8723af70b8518c1a9ae43e650afb433e078470 (patch)
tree00e7d03fd91ecf0b1ea3a4754582f136a9c2beb4 /lib
parentec86deadf0483d52686c4b2a89c5bb79959e7e28 (diff)
downloadrails-0c8723af70b8518c1a9ae43e650afb433e078470.tar.gz
rails-0c8723af70b8518c1a9ae43e650afb433e078470.tar.bz2
rails-0c8723af70b8518c1a9ae43e650afb433e078470.zip
visitors can define their own cache strategy for dispatch. fixes #57
Diffstat (limited to 'lib')
-rw-r--r--lib/arel/visitors/visitor.rb12
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/arel/visitors/visitor.rb b/lib/arel/visitors/visitor.rb
index c9cdf34adb..8f9dd929e1 100644
--- a/lib/arel/visitors/visitor.rb
+++ b/lib/arel/visitors/visitor.rb
@@ -11,15 +11,19 @@ module Arel
hash[klass] = "visit_#{(klass.name || '').gsub('::', '_')}"
end
+ def dispatch
+ DISPATCH
+ end
+
def visit object
- send DISPATCH[object.class], object
+ send dispatch[object.class], object
rescue NoMethodError => e
- raise e if respond_to?(DISPATCH[object.class], true)
+ raise e if respond_to?(dispatch[object.class], true)
superklass = object.class.ancestors.find { |klass|
- respond_to?(DISPATCH[klass], true)
+ respond_to?(dispatch[klass], true)
}
raise(TypeError, "Cannot visit #{object.class}") unless superklass
- DISPATCH[object.class] = DISPATCH[superklass]
+ dispatch[object.class] = dispatch[superklass]
retry
end
end