aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikolay Ponomarev <itsnikolay@gmail.com>2017-12-27 22:21:32 +0300
committerNikolay Ponomarev <itsnikolay@gmail.com>2017-12-27 22:30:06 +0300
commitc41c909decde88156215e07e5d1d52898a3d5aa4 (patch)
treecdbf21b644d22758244a273805a3dd3a674ddd89
parentaa11ad9129b65e637c05cc4b26a2cbbff6f143c2 (diff)
downloadrails-c41c909decde88156215e07e5d1d52898a3d5aa4.tar.gz
rails-c41c909decde88156215e07e5d1d52898a3d5aa4.tar.bz2
rails-c41c909decde88156215e07e5d1d52898a3d5aa4.zip
Reduce `Reduce`
Remove `Arel::Visitors::Reduce` because it almost completely duplicates `Arel::Visitors::Visitor`
-rw-r--r--arel.gemspec2
-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
-rw-r--r--test/visitors/test_to_sql.rb2
5 files changed, 9 insertions, 39 deletions
diff --git a/arel.gemspec b/arel.gemspec
index f914d1a5ca..4ed41c3d4c 100644
--- a/arel.gemspec
+++ b/arel.gemspec
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
s.rdoc_options = ["--main", "README.md"]
s.extra_rdoc_files = ["History.txt", "MIT-LICENSE.txt", "README.md"]
- s.files = ["History.txt","MIT-LICENSE.txt","README.md","lib/arel.rb","lib/arel/alias_predication.rb","lib/arel/attributes.rb","lib/arel/attributes/attribute.rb","lib/arel/collectors/bind.rb","lib/arel/collectors/composite.rb","lib/arel/collectors/plain_string.rb","lib/arel/collectors/sql_string.rb","lib/arel/collectors/substitute_binds.rb","lib/arel/compatibility/wheres.rb","lib/arel/crud.rb","lib/arel/delete_manager.rb","lib/arel/errors.rb","lib/arel/expressions.rb","lib/arel/factory_methods.rb","lib/arel/insert_manager.rb","lib/arel/math.rb","lib/arel/nodes.rb","lib/arel/nodes/and.rb","lib/arel/nodes/ascending.rb","lib/arel/nodes/binary.rb","lib/arel/nodes/bind_param.rb","lib/arel/nodes/case.rb","lib/arel/nodes/casted.rb","lib/arel/nodes/count.rb","lib/arel/nodes/delete_statement.rb","lib/arel/nodes/descending.rb","lib/arel/nodes/equality.rb","lib/arel/nodes/extract.rb","lib/arel/nodes/false.rb","lib/arel/nodes/full_outer_join.rb","lib/arel/nodes/function.rb","lib/arel/nodes/grouping.rb","lib/arel/nodes/in.rb","lib/arel/nodes/infix_operation.rb","lib/arel/nodes/inner_join.rb","lib/arel/nodes/insert_statement.rb","lib/arel/nodes/join_source.rb","lib/arel/nodes/matches.rb","lib/arel/nodes/named_function.rb","lib/arel/nodes/node.rb","lib/arel/nodes/outer_join.rb","lib/arel/nodes/over.rb","lib/arel/nodes/regexp.rb","lib/arel/nodes/right_outer_join.rb","lib/arel/nodes/select_core.rb","lib/arel/nodes/select_statement.rb","lib/arel/nodes/sql_literal.rb","lib/arel/nodes/string_join.rb","lib/arel/nodes/table_alias.rb","lib/arel/nodes/terminal.rb","lib/arel/nodes/true.rb","lib/arel/nodes/unary.rb","lib/arel/nodes/unary_operation.rb","lib/arel/nodes/unqualified_column.rb","lib/arel/nodes/update_statement.rb","lib/arel/nodes/values.rb","lib/arel/nodes/values_list.rb","lib/arel/nodes/window.rb","lib/arel/nodes/with.rb","lib/arel/order_predications.rb","lib/arel/predications.rb","lib/arel/select_manager.rb","lib/arel/table.rb","lib/arel/tree_manager.rb","lib/arel/update_manager.rb","lib/arel/visitors.rb","lib/arel/visitors/depth_first.rb","lib/arel/visitors/dot.rb","lib/arel/visitors/ibm_db.rb","lib/arel/visitors/informix.rb","lib/arel/visitors/mssql.rb","lib/arel/visitors/mysql.rb","lib/arel/visitors/oracle.rb","lib/arel/visitors/oracle12.rb","lib/arel/visitors/postgresql.rb","lib/arel/visitors/reduce.rb","lib/arel/visitors/sqlite.rb","lib/arel/visitors/to_sql.rb","lib/arel/visitors/visitor.rb","lib/arel/visitors/where_sql.rb","lib/arel/window_predications.rb"]
+ s.files = ["History.txt","MIT-LICENSE.txt","README.md","lib/arel.rb","lib/arel/alias_predication.rb","lib/arel/attributes.rb","lib/arel/attributes/attribute.rb","lib/arel/collectors/bind.rb","lib/arel/collectors/composite.rb","lib/arel/collectors/plain_string.rb","lib/arel/collectors/sql_string.rb","lib/arel/collectors/substitute_binds.rb","lib/arel/compatibility/wheres.rb","lib/arel/crud.rb","lib/arel/delete_manager.rb","lib/arel/errors.rb","lib/arel/expressions.rb","lib/arel/factory_methods.rb","lib/arel/insert_manager.rb","lib/arel/math.rb","lib/arel/nodes.rb","lib/arel/nodes/and.rb","lib/arel/nodes/ascending.rb","lib/arel/nodes/binary.rb","lib/arel/nodes/bind_param.rb","lib/arel/nodes/case.rb","lib/arel/nodes/casted.rb","lib/arel/nodes/count.rb","lib/arel/nodes/delete_statement.rb","lib/arel/nodes/descending.rb","lib/arel/nodes/equality.rb","lib/arel/nodes/extract.rb","lib/arel/nodes/false.rb","lib/arel/nodes/full_outer_join.rb","lib/arel/nodes/function.rb","lib/arel/nodes/grouping.rb","lib/arel/nodes/in.rb","lib/arel/nodes/infix_operation.rb","lib/arel/nodes/inner_join.rb","lib/arel/nodes/insert_statement.rb","lib/arel/nodes/join_source.rb","lib/arel/nodes/matches.rb","lib/arel/nodes/named_function.rb","lib/arel/nodes/node.rb","lib/arel/nodes/outer_join.rb","lib/arel/nodes/over.rb","lib/arel/nodes/regexp.rb","lib/arel/nodes/right_outer_join.rb","lib/arel/nodes/select_core.rb","lib/arel/nodes/select_statement.rb","lib/arel/nodes/sql_literal.rb","lib/arel/nodes/string_join.rb","lib/arel/nodes/table_alias.rb","lib/arel/nodes/terminal.rb","lib/arel/nodes/true.rb","lib/arel/nodes/unary.rb","lib/arel/nodes/unary_operation.rb","lib/arel/nodes/unqualified_column.rb","lib/arel/nodes/update_statement.rb","lib/arel/nodes/values.rb","lib/arel/nodes/values_list.rb","lib/arel/nodes/window.rb","lib/arel/nodes/with.rb","lib/arel/order_predications.rb","lib/arel/predications.rb","lib/arel/select_manager.rb","lib/arel/table.rb","lib/arel/tree_manager.rb","lib/arel/update_manager.rb","lib/arel/visitors.rb","lib/arel/visitors/depth_first.rb","lib/arel/visitors/dot.rb","lib/arel/visitors/ibm_db.rb","lib/arel/visitors/informix.rb","lib/arel/visitors/mssql.rb","lib/arel/visitors/mysql.rb","lib/arel/visitors/oracle.rb","lib/arel/visitors/oracle12.rb","lib/arel/visitors/postgresql.rb","lib/arel/visitors/sqlite.rb","lib/arel/visitors/to_sql.rb","lib/arel/visitors/visitor.rb","lib/arel/visitors/where_sql.rb","lib/arel/window_predications.rb"]
s.require_paths = ["lib"]
s.add_development_dependency('minitest', '~> 5.4')
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|
diff --git a/test/visitors/test_to_sql.rb b/test/visitors/test_to_sql.rb
index e95c0666b4..eb6eedc55d 100644
--- a/test/visitors/test_to_sql.rb
+++ b/test/visitors/test_to_sql.rb
@@ -31,7 +31,7 @@ module Arel
it 'can define a dispatch method' do
visited = false
- viz = Class.new(Arel::Visitors::Reduce) {
+ viz = Class.new(Arel::Visitors::Visitor) {
define_method(:hello) do |node, c|
visited = true
end