From f62a7267c551d216297bec9f0496738b8e27dcae Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 30 Nov 2010 11:06:09 -0800 Subject: [PATCH] adding deprecated support for walking ancestor trees --- History.txt | 5 +++++ lib/arel/visitors/visitor.rb | 7 +++++++ test/visitors/test_to_sql.rb | 5 +++++ 3 files changed, 17 insertions(+) diff --git a/History.txt b/History.txt index e981c26126..2f8934fcb9 100644 --- a/History.txt +++ b/History.txt @@ -11,6 +11,11 @@ * Nodes::Node#not factory method added for creating Nodes::Not nodes * Added an As node +* Deprecations + + * Support for Subclasses of core classes will be removed in ARel version + 2.2.0 + == 2.0.4 * Bug fixes diff --git a/lib/arel/visitors/visitor.rb b/lib/arel/visitors/visitor.rb index 510d50399b..b0d16ffe4e 100644 --- a/lib/arel/visitors/visitor.rb +++ b/lib/arel/visitors/visitor.rb @@ -13,6 +13,13 @@ module Arel def visit object send DISPATCH[object.class], object + rescue NoMethodError + warn "visiting #{object.class} via superclass, this will be removed in arel 2.2.0" if $VERBOSE + superklass = object.class.ancestors.find { |klass| + respond_to?(DISPATCH[klass], true) + } + DISPATCH[object.class] = DISPATCH[superklass] + retry end end end diff --git a/test/visitors/test_to_sql.rb b/test/visitors/test_to_sql.rb index 037fca9931..1c5c8eac0c 100644 --- a/test/visitors/test_to_sql.rb +++ b/test/visitors/test_to_sql.rb @@ -21,6 +21,11 @@ module Arel end end + it "should visit string subclass" do + @visitor.accept(Class.new(String).new(":'(")) + @visitor.accept(Class.new(Class.new(String)).new(":'(")) + end + it "should visit_Class" do @visitor.accept(DateTime).must_equal "'DateTime'" end