1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/lib/arel/tree_manager.rb
2014-04-08 12:03:52 -07:00

44 lines
750 B
Ruby

require 'arel/collectors/sql_string'
module Arel
class TreeManager
include Arel::FactoryMethods
attr_reader :ast, :engine
attr_accessor :bind_values
def initialize engine
@engine = engine
@ctx = nil
@bind_values = []
end
def to_dot
Visitors::Dot.new.accept @ast
end
def visitor
engine.connection.visitor
end
def to_sql
collector = Arel::Collectors::SQLString.new
collector = visitor.accept @ast, collector
collector.value
end
def initialize_copy other
super
@ast = @ast.clone
end
def where expr
if Arel::TreeManager === expr
expr = expr.ast
end
@ctx.wheres << expr
self
end
end
end