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

45 lines
750 B
Ruby
Raw Normal View History

require 'arel/collectors/sql_string'
2010-08-12 19:19:54 -04:00
module Arel
class TreeManager
include Arel::FactoryMethods
2010-08-13 15:26:06 -04:00
attr_reader :ast, :engine
2010-09-23 18:26:08 -04:00
2014-01-14 17:32:32 -05:00
attr_accessor :bind_values
2010-08-12 19:19:54 -04:00
def initialize engine
@engine = engine
@ctx = nil
2014-01-14 17:32:32 -05:00
@bind_values = []
2010-08-12 19:19:54 -04:00
end
def to_dot
2010-11-05 17:09:09 -04:00
Visitors::Dot.new.accept @ast
end
def visitor
engine.connection.visitor
end
2010-08-12 19:19:54 -04:00
def to_sql
collector = Arel::Collectors::SQLString.new
collector = visitor.accept @ast, collector
collector.value
2010-08-12 19:19:54 -04:00
end
def initialize_copy other
super
2010-11-05 17:09:09 -04:00
@ast = @ast.clone
end
2010-12-07 13:46:30 -05:00
def where expr
if Arel::TreeManager === expr
expr = expr.ast
end
@ctx.wheres << expr
self
end
2010-08-12 19:19:54 -04:00
end
end