1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activerecord/lib/arel/tree_manager.rb

61 lines
1.1 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2018-02-24 01:45:50 -05:00
2018-02-24 02:41:47 -05:00
module Arel # :nodoc: all
2010-08-12 19:19:54 -04:00
class TreeManager
include Arel::FactoryMethods
2010-08-13 15:26:06 -04:00
module StatementMethods
def take(limit)
@ast.limit = Nodes::Limit.new(Nodes.build_quoted(limit)) if limit
self
end
def offset(offset)
@ast.offset = Nodes::Offset.new(Nodes.build_quoted(offset)) if offset
self
end
def order(*expr)
@ast.orders = expr
self
end
def key=(key)
@ast.key = Nodes.build_quoted(key)
end
def key
@ast.key
end
def wheres=(exprs)
@ast.wheres = exprs
end
def where(expr)
@ast.wheres << expr
self
end
end
attr_reader :ast
2010-09-23 18:26:08 -04:00
def to_dot
collector = Arel::Collectors::PlainString.new
collector = Visitors::Dot.new.accept @ast, collector
collector.value
end
2018-02-24 01:45:50 -05:00
def to_sql(engine = Table.engine)
collector = Arel::Collectors::SQLString.new
collector = engine.connection.visitor.accept @ast, collector
collector.value
2010-08-12 19:19:54 -04:00
end
2018-02-24 01:45:50 -05:00
def initialize_copy(other)
super
2010-11-05 17:09:09 -04:00
@ast = @ast.clone
end
2010-08-12 19:19:54 -04:00
end
end