forked from brynary/arel
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
push reduction visitors to a reduction base class
this lets our old depth first and dot visitors to work normally
- Loading branch information
1 parent
6ae60fd
commit a6a7c75
Showing
6 changed files
with
37 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
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 | ||
send dispatch[object.class], object, collector | ||
rescue NoMethodError => e | ||
raise e if respond_to?(dispatch[object.class], 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters