Skip to content
This repository
Browse code

renaming @head to @ast

  • Loading branch information...
commit a1a01e2bb301a7a4ae5c5cdcc27ece9f7edf6c66 1 parent 424e39d
Aaron Patterson tenderlove authored
4 lib/arel/crud.rb
@@ -13,8 +13,8 @@ def update values
13 13 end
14 14 um.table relation
15 15 um.set values
16   - um.take @head.limit
17   - um.order(*@head.orders)
  16 + um.take @ast.limit
  17 + um.order(*@ast.orders)
18 18 um.wheres = @ctx.wheres
19 19
20 20 @engine.connection.update um.to_sql, 'AREL'
8 lib/arel/delete_manager.rb
@@ -2,21 +2,21 @@ module Arel
2 2 class DeleteManager < Arel::TreeManager
3 3 def initialize engine
4 4 super
5   - @head = Nodes::DeleteStatement.new
  5 + @ast = Nodes::DeleteStatement.new
6 6 end
7 7
8 8 def from relation
9   - @head.relation = relation
  9 + @ast.relation = relation
10 10 self
11 11 end
12 12
13 13 def where expression
14   - @head.wheres << expression
  14 + @ast.wheres << expression
15 15 self
16 16 end
17 17
18 18 def wheres= list
19   - @head.wheres = list
  19 + @ast.wheres = list
20 20 end
21 21 end
22 22 end
16 lib/arel/insert_manager.rb
@@ -2,32 +2,32 @@ module Arel
2 2 class InsertManager < Arel::TreeManager
3 3 def initialize engine
4 4 super
5   - @head = Nodes::InsertStatement.new
  5 + @ast = Nodes::InsertStatement.new
6 6 end
7 7
8 8 def into table
9   - @head.relation = table
  9 + @ast.relation = table
10 10 self
11 11 end
12 12
13   - def columns; @head.columns end
14   - def values= val; @head.values = val; end
  13 + def columns; @ast.columns end
  14 + def values= val; @ast.values = val; end
15 15
16 16 def insert fields
17 17 return if fields.empty?
18 18
19 19 if String === fields
20   - @head.values = SqlLiteral.new(fields)
  20 + @ast.values = SqlLiteral.new(fields)
21 21 else
22   - @head.relation ||= fields.first.first.relation
  22 + @ast.relation ||= fields.first.first.relation
23 23
24 24 values = []
25 25
26 26 fields.each do |column, value|
27   - @head.columns << column
  27 + @ast.columns << column
28 28 values << value
29 29 end
30   - @head.values = Nodes::Values.new values, @head.columns
  30 + @ast.values = Nodes::Values.new values, @ast.columns
31 31 end
32 32 end
33 33 end
20 lib/arel/select_manager.rb
@@ -4,13 +4,13 @@ class SelectManager < Arel::TreeManager
4 4
5 5 def initialize engine, table = nil
6 6 super(engine)
7   - @head = Nodes::SelectStatement.new
8   - @ctx = @head.cores.last
  7 + @ast = Nodes::SelectStatement.new
  8 + @ctx = @ast.cores.last
9 9 from table
10 10 end
11 11
12 12 def taken
13   - @head.limit
  13 + @ast.limit
14 14 end
15 15
16 16 def constraints
@@ -18,7 +18,7 @@ def constraints
18 18 end
19 19
20 20 def skip amount
21   - @head.offset = Nodes::Offset.new(amount)
  21 + @ast.offset = Nodes::Offset.new(amount)
22 22 self
23 23 end
24 24
@@ -31,12 +31,12 @@ def where_clauses
31 31 def lock locking = true
32 32 # FIXME: do we even need to store this? If locking is +false+ shouldn't
33 33 # we just remove the node from the AST?
34   - @head.lock = Nodes::Lock.new
  34 + @ast.lock = Nodes::Lock.new
35 35 self
36 36 end
37 37
38 38 def locked
39   - @head.lock
  39 + @ast.lock
40 40 end
41 41
42 42 def on *exprs
@@ -108,14 +108,14 @@ def where expr
108 108
109 109 def order *expr
110 110 # FIXME: We SHOULD NOT be converting these to SqlLiteral automatically
111   - @head.orders.concat expr.map { |x|
  111 + @ast.orders.concat expr.map { |x|
112 112 String === x || Symbol === x ? Nodes::SqlLiteral.new(x.to_s) : x
113 113 }
114 114 self
115 115 end
116 116
117 117 def orders
118   - @head.orders
  118 + @ast.orders
119 119 end
120 120
121 121 def wheres
@@ -130,7 +130,7 @@ def where_sql
130 130 end
131 131
132 132 def take limit
133   - @head.limit = limit
  133 + @ast.limit = limit
134 134 self
135 135 end
136 136
@@ -142,7 +142,7 @@ def join_sql
142 142 end
143 143
144 144 def order_clauses
145   - Visitors::OrderClauses.new(@engine).accept(@head).map { |x|
  145 + Visitors::OrderClauses.new(@engine).accept(@ast).map { |x|
146 146 Nodes::SqlLiteral.new x
147 147 }
148 148 end
7 lib/arel/tree_manager.rb
@@ -4,6 +4,7 @@ class TreeManager
4 4 include Arel::Relation
5 5
6 6 attr_accessor :visitor
  7 + attr_reader :ast
7 8
8 9 def initialize engine
9 10 @engine = engine
@@ -11,16 +12,16 @@ def initialize engine
11 12 end
12 13
13 14 def to_dot
14   - Visitors::Dot.new.accept @head
  15 + Visitors::Dot.new.accept @ast
15 16 end
16 17
17 18 def to_sql
18   - @visitor.accept @head
  19 + @visitor.accept @ast
19 20 end
20 21
21 22 def initialize_copy other
22 23 super
23   - @head = @head.clone
  24 + @ast = @ast.clone
24 25 end
25 26 end
26 27 end
16 lib/arel/update_manager.rb
@@ -2,40 +2,40 @@ module Arel
2 2 class UpdateManager < Arel::TreeManager
3 3 def initialize engine
4 4 super
5   - @head = Nodes::UpdateStatement.new
  5 + @ast = Nodes::UpdateStatement.new
6 6 end
7 7
8 8 def take limit
9   - @head.limit = limit
  9 + @ast.limit = limit
10 10 self
11 11 end
12 12
13 13 def order *expr
14   - @head.orders = expr
  14 + @ast.orders = expr
15 15 self
16 16 end
17 17
18 18 ###
19 19 # UPDATE +table+
20 20 def table table
21   - @head.relation = table
  21 + @ast.relation = table
22 22 self
23 23 end
24 24
25 25 def wheres= exprs
26   - @head.wheres = exprs
  26 + @ast.wheres = exprs
27 27 end
28 28
29 29 def where expr
30   - @head.wheres << expr
  30 + @ast.wheres << expr
31 31 self
32 32 end
33 33
34 34 def set values
35 35 if String === values
36   - @head.values = [values]
  36 + @ast.values = [values]
37 37 else
38   - @head.values = values.map { |column,value|
  38 + @ast.values = values.map { |column,value|
39 39 Nodes::Assignment.new(
40 40 Nodes::UnqualifiedColumn.new(column),
41 41 value
9 test/test_select_manager.rb
@@ -130,6 +130,15 @@ def execute sql, name = nil, *args
130 130 end
131 131 end
132 132
  133 + describe 'ast' do
  134 + it 'should return the ast' do
  135 + table = Table.new :users
  136 + mgr = table.from table
  137 + ast = mgr.ast
  138 + mgr.visitor.accept(ast).must_equal mgr.to_sql
  139 + end
  140 + end
  141 +
133 142 describe 'taken' do
134 143 it 'should return limit' do
135 144 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.