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/update_manager.rb
2010-09-23 15:27:17 -07:00

48 lines
797 B
Ruby

module Arel
class UpdateManager < Arel::TreeManager
def initialize engine
super
@head = Nodes::UpdateStatement.new
end
def take limit
@head.limit = limit
self
end
def order *expr
@head.orders = expr
self
end
###
# UPDATE +table+
def table table
@head.relation = table
self
end
def wheres= exprs
@head.wheres = exprs
end
def where expr
@head.wheres << expr
self
end
def set values
if String === values
@head.values = [values]
else
@head.values = values.map { |column,value|
Nodes::Assignment.new(
Nodes::UnqualifiedColumn.new(column),
value
)
}
end
self
end
end
end