2014-04-08 15:03:52 -04:00
|
|
|
require 'arel/collectors/sql_string'
|
|
|
|
|
2010-08-12 19:19:54 -04:00
|
|
|
module Arel
|
|
|
|
class TreeManager
|
2010-12-07 14:44:32 -05:00
|
|
|
include Arel::FactoryMethods
|
2010-08-13 15:26:06 -04:00
|
|
|
|
2010-11-05 19:33:26 -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
|
2011-08-08 18:23:51 -04:00
|
|
|
@engine = engine
|
|
|
|
@ctx = nil
|
2014-01-14 17:32:32 -05:00
|
|
|
@bind_values = []
|
2010-08-12 19:19:54 -04:00
|
|
|
end
|
|
|
|
|
2010-08-16 17:09:48 -04:00
|
|
|
def to_dot
|
2010-11-05 17:09:09 -04:00
|
|
|
Visitors::Dot.new.accept @ast
|
2010-08-16 17:09:48 -04:00
|
|
|
end
|
|
|
|
|
2011-08-08 18:23:51 -04:00
|
|
|
def visitor
|
|
|
|
engine.connection.visitor
|
|
|
|
end
|
|
|
|
|
2010-08-12 19:19:54 -04:00
|
|
|
def to_sql
|
2014-04-08 15:03:52 -04:00
|
|
|
collector = Arel::Collectors::SQLString.new
|
|
|
|
collector = visitor.accept @ast, collector
|
|
|
|
collector.value
|
2010-08-12 19:19:54 -04:00
|
|
|
end
|
2010-08-16 23:33:41 -04:00
|
|
|
|
|
|
|
def initialize_copy other
|
|
|
|
super
|
2010-11-05 17:09:09 -04:00
|
|
|
@ast = @ast.clone
|
2010-08-16 23:33:41 -04:00
|
|
|
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
|