Skip to content
Browse files

renaming @head to @ast

  • Loading branch information...
1 parent 424e39d commit a1a01e2bb301a7a4ae5c5cdcc27ece9f7edf6c66 @tenderlove tenderlove committed Nov 5, 2010
View
4 lib/arel/crud.rb
@@ -13,8 +13,8 @@ def update values
end
um.table relation
um.set values
- um.take @head.limit
- um.order(*@head.orders)
+ um.take @ast.limit
+ um.order(*@ast.orders)
um.wheres = @ctx.wheres
@engine.connection.update um.to_sql, 'AREL'
View
8 lib/arel/delete_manager.rb
@@ -2,21 +2,21 @@ module Arel
class DeleteManager < Arel::TreeManager
def initialize engine
super
- @head = Nodes::DeleteStatement.new
+ @ast = Nodes::DeleteStatement.new
end
def from relation
- @head.relation = relation
+ @ast.relation = relation
self
end
def where expression
- @head.wheres << expression
+ @ast.wheres << expression
self
end
def wheres= list
- @head.wheres = list
+ @ast.wheres = list
end
end
end
View
16 lib/arel/insert_manager.rb
@@ -2,32 +2,32 @@ module Arel
class InsertManager < Arel::TreeManager
def initialize engine
super
- @head = Nodes::InsertStatement.new
+ @ast = Nodes::InsertStatement.new
end
def into table
- @head.relation = table
+ @ast.relation = table
self
end
- def columns; @head.columns end
- def values= val; @head.values = val; end
+ def columns; @ast.columns end
+ def values= val; @ast.values = val; end
def insert fields
return if fields.empty?
if String === fields
- @head.values = SqlLiteral.new(fields)
+ @ast.values = SqlLiteral.new(fields)
else
- @head.relation ||= fields.first.first.relation
+ @ast.relation ||= fields.first.first.relation
values = []
fields.each do |column, value|
- @head.columns << column
+ @ast.columns << column
values << value
end
- @head.values = Nodes::Values.new values, @head.columns
+ @ast.values = Nodes::Values.new values, @ast.columns
end
end
end
View
20 lib/arel/select_manager.rb
@@ -4,21 +4,21 @@ class SelectManager < Arel::TreeManager
def initialize engine, table = nil
super(engine)
- @head = Nodes::SelectStatement.new
- @ctx = @head.cores.last
+ @ast = Nodes::SelectStatement.new
+ @ctx = @ast.cores.last
from table
end
def taken
- @head.limit
+ @ast.limit
end
def constraints
@ctx.wheres
end
def skip amount
- @head.offset = Nodes::Offset.new(amount)
+ @ast.offset = Nodes::Offset.new(amount)
self
end
@@ -31,12 +31,12 @@ def where_clauses
def lock locking = true
# FIXME: do we even need to store this? If locking is +false+ shouldn't
# we just remove the node from the AST?
- @head.lock = Nodes::Lock.new
+ @ast.lock = Nodes::Lock.new
self
end
def locked
- @head.lock
+ @ast.lock
end
def on *exprs
@@ -108,14 +108,14 @@ def where expr
def order *expr
# FIXME: We SHOULD NOT be converting these to SqlLiteral automatically
- @head.orders.concat expr.map { |x|
+ @ast.orders.concat expr.map { |x|
String === x || Symbol === x ? Nodes::SqlLiteral.new(x.to_s) : x
}
self
end
def orders
- @head.orders
+ @ast.orders
end
def wheres
@@ -130,7 +130,7 @@ def where_sql
end
def take limit
- @head.limit = limit
+ @ast.limit = limit
self
end
@@ -142,7 +142,7 @@ def join_sql
end
def order_clauses
- Visitors::OrderClauses.new(@engine).accept(@head).map { |x|
+ Visitors::OrderClauses.new(@engine).accept(@ast).map { |x|
Nodes::SqlLiteral.new x
}
end
View
7 lib/arel/tree_manager.rb
@@ -4,23 +4,24 @@ class TreeManager
include Arel::Relation
attr_accessor :visitor
+ attr_reader :ast
def initialize engine
@engine = engine
@visitor = Visitors.visitor_for @engine
end
def to_dot
- Visitors::Dot.new.accept @head
+ Visitors::Dot.new.accept @ast
end
def to_sql
- @visitor.accept @head
+ @visitor.accept @ast
end
def initialize_copy other
super
- @head = @head.clone
+ @ast = @ast.clone
end
end
end
View
16 lib/arel/update_manager.rb
@@ -2,40 +2,40 @@ module Arel
class UpdateManager < Arel::TreeManager
def initialize engine
super
- @head = Nodes::UpdateStatement.new
+ @ast = Nodes::UpdateStatement.new
end
def take limit
- @head.limit = limit
+ @ast.limit = limit
self
end
def order *expr
- @head.orders = expr
+ @ast.orders = expr
self
end
###
# UPDATE +table+
def table table
- @head.relation = table
+ @ast.relation = table
self
end
def wheres= exprs
- @head.wheres = exprs
+ @ast.wheres = exprs
end
def where expr
- @head.wheres << expr
+ @ast.wheres << expr
self
end
def set values
if String === values
- @head.values = [values]
+ @ast.values = [values]
else
- @head.values = values.map { |column,value|
+ @ast.values = values.map { |column,value|
Nodes::Assignment.new(
Nodes::UnqualifiedColumn.new(column),
value
View
9 test/test_select_manager.rb
@@ -130,6 +130,15 @@ def execute sql, name = nil, *args
end
end
+ describe 'ast' do
+ it 'should return the ast' do
+ table = Table.new :users
+ mgr = table.from table
+ ast = mgr.ast
+ mgr.visitor.accept(ast).must_equal mgr.to_sql
+ end
+ end
+
describe 'taken' do
it 'should return limit' do
manager = Arel::SelectManager.new Table.engine

0 comments on commit a1a01e2

Please sign in to comment.
Something went wrong with that request. Please try again.