From c41c909decde88156215e07e5d1d52898a3d5aa4 Mon Sep 17 00:00:00 2001 From: Nikolay Ponomarev Date: Wed, 27 Dec 2017 22:21:32 +0300 Subject: Reduce `Reduce` Remove `Arel::Visitors::Reduce` because it almost completely duplicates `Arel::Visitors::Visitor` --- lib/arel/visitors/reduce.rb | 27 --------------------------- lib/arel/visitors/to_sql.rb | 3 +-- lib/arel/visitors/visitor.rb | 14 ++++++-------- 3 files changed, 7 insertions(+), 37 deletions(-) delete mode 100644 lib/arel/visitors/reduce.rb (limited to 'lib/arel') 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| -- cgit v1.2.3