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
2010-08-12 21:21:20 -07:00

38 lines
612 B
Ruby

module Arel
class TreeManager
def initialize engine
@engine = engine
@selects = []
# default to Select
@stmt = Nodes::SelectStatement.new
@core = @stmt.cores.last
@selects << @stmt
end
def from table
@core.froms << table
self
end
def project projection
@core.projections << projection
self
end
def where expr
@core.wheres << expr
self
end
def take limit
@stmt.limit = limit
self
end
def to_sql
viz = Visitors::ToSql.new @engine
viz.accept @stmt
end
end
end