aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/visitors
diff options
context:
space:
mode:
Diffstat (limited to 'lib/arel/visitors')
-rw-r--r--lib/arel/visitors/reduce.rb27
-rw-r--r--lib/arel/visitors/to_sql.rb3
-rw-r--r--lib/arel/visitors/visitor.rb14
3 files changed, 7 insertions, 37 deletions
diff --git a/lib/arel/visitors/reduce.rb b/lib/arel/visitors/reduce.rb
deleted file mode 100644
index 1156b780f0..0000000000
--- a/lib/arel/visitors/reduce.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-# frozen_string_literal: true
-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
- dispatch_method = dispatch[object.class]
- send dispatch_method, object, collector
- rescue NoMethodError => e
- raise e if respond_to?(dispatch_method, true)
- superklass = object.class.ancestors.find { |klass|
- respond_to?(dispatch[klass], true)
- }
- raise(TypeError, "Cannot visit #{object.class}") unless superklass
- dispatch[object.class] = dispatch[superklass]
- retry
- end
- end
- end
-end
diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb
index 6aaaa19e6e..f8c239e8ef 100644
--- a/lib/arel/visitors/to_sql.rb
+++ b/lib/arel/visitors/to_sql.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'bigdecimal'
require 'date'
-require 'arel/visitors/reduce'
module Arel
module Visitors
@@ -11,7 +10,7 @@ module Arel
end
end
- class ToSql < Arel::Visitors::Reduce
+ class ToSql < Arel::Visitors::Visitor
##
# This is some roflscale crazy stuff. I'm roflscaling this because
# building SQL queries is a hotspot. I will explain the roflscale so that
diff --git a/lib/arel/visitors/visitor.rb b/lib/arel/visitors/visitor.rb
index 2690c98e3c..f156be9a0a 100644
--- a/lib/arel/visitors/visitor.rb
+++ b/lib/arel/visitors/visitor.rb
@@ -6,12 +6,14 @@ module Arel
@dispatch = get_dispatch_cache
end
- def accept object
- visit object
+ def accept object, *args
+ visit object, *args
end
private
+ attr_reader :dispatch
+
def self.dispatch_cache
Hash.new do |hash, klass|
hash[klass] = "visit_#{(klass.name || '').gsub('::', '_')}"
@@ -22,13 +24,9 @@ module Arel
self.class.dispatch_cache
end
- def dispatch
- @dispatch
- end
-
- def visit object
+ def visit object, *args
dispatch_method = dispatch[object.class]
- send dispatch_method, object
+ send dispatch_method, object, *args
rescue NoMethodError => e
raise e if respond_to?(dispatch_method, true)
superklass = object.class.ancestors.find { |klass|