Class: Seaquel::StatementGatherer
- Inherits:
-
Object
- Object
- Seaquel::StatementGatherer
- Extended by:
- Forwardable
- Defined in:
- lib/seaquel/statement_gatherer.rb
Overview
Visits a statement AST and issues a statement.
Instance Attribute Summary collapse
-
#current_join ⇒ Object
readonly
Returns the value of attribute current_join.
Instance Method Summary collapse
-
#initialize(statement, quoter) ⇒ StatementGatherer
constructor
A new instance of StatementGatherer.
- #visit_delete(parent) ⇒ Object
- #visit_fields(parent, fields) ⇒ Object
- #visit_from(parent, *args) ⇒ Object
- #visit_insert(parent) ⇒ Object
- #visit_into(parent, table) ⇒ Object
- #visit_join(parent, tables) ⇒ Object
- #visit_limit(parent, n) ⇒ Object
- #visit_offset(parent, n) ⇒ Object
- #visit_on(parent, exps) ⇒ Object
- #visit_order_by(parent, list) ⇒ Object
- #visit_project(parent, fields) ⇒ Object
- #visit_select(parent) ⇒ Object
- #visit_set(parent, assign_list) ⇒ Object
- #visit_update(parent, table) ⇒ Object
- #visit_values(parent, values) ⇒ Object
- #visit_where(parent, expression) ⇒ Object
Constructor Details
#initialize(statement, quoter) ⇒ StatementGatherer
9 10 11 12 13 |
# File 'lib/seaquel/statement_gatherer.rb', line 9 def initialize statement, quoter @statement = statement @quoter = quoter @current_join = nil end |
Instance Attribute Details
#current_join ⇒ Object (readonly)
Returns the value of attribute current_join.
7 8 9 |
# File 'lib/seaquel/statement_gatherer.rb', line 7 def current_join @current_join end |
Instance Method Details
#visit_delete(parent) ⇒ Object
90 91 92 93 94 |
# File 'lib/seaquel/statement_gatherer.rb', line 90 def visit_delete parent continue(parent) s.set_type(:delete) end |
#visit_fields(parent, fields) ⇒ Object
84 85 86 87 88 |
# File 'lib/seaquel/statement_gatherer.rb', line 84 def visit_fields parent, fields continue(parent) s.fields.concat(fields) end |
#visit_from(parent, *args) ⇒ Object
17 18 19 20 21 |
# File 'lib/seaquel/statement_gatherer.rb', line 17 def visit_from parent, *args s.from.concat(args) continue(parent) end |
#visit_insert(parent) ⇒ Object
69 70 71 72 73 |
# File 'lib/seaquel/statement_gatherer.rb', line 69 def visit_insert parent continue(parent) s.set_type(:insert) end |
#visit_into(parent, table) ⇒ Object
74 75 76 77 78 |
# File 'lib/seaquel/statement_gatherer.rb', line 74 def visit_into parent, table continue(parent) s.set_target(table) end |
#visit_join(parent, tables) ⇒ Object
55 56 57 58 59 |
# File 'lib/seaquel/statement_gatherer.rb', line 55 def visit_join parent, tables continue(parent) @current_join = s.join(tables) end |
#visit_limit(parent, n) ⇒ Object
101 102 103 104 105 |
# File 'lib/seaquel/statement_gatherer.rb', line 101 def visit_limit parent, n continue(parent) s.set_limit(n) end |
#visit_offset(parent, n) ⇒ Object
96 97 98 99 100 |
# File 'lib/seaquel/statement_gatherer.rb', line 96 def visit_offset parent, n continue(parent) s.set_offset(n) end |
#visit_on(parent, exps) ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/seaquel/statement_gatherer.rb', line 60 def visit_on(parent, exps) continue(parent) raise InvalidExpression, ".on without a .join encoutered" \ unless current_join current_join.on(exps) end |
#visit_order_by(parent, list) ⇒ Object
32 33 34 35 36 |
# File 'lib/seaquel/statement_gatherer.rb', line 32 def visit_order_by parent, list continue(parent) s.order_by.replace(list) end |
#visit_project(parent, fields) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/seaquel/statement_gatherer.rb', line 25 def visit_project parent, fields continue(parent) # Since the tree is processed in lifo order, we need to only apply the # very last project. s.project.replace(fields) end |
#visit_select(parent) ⇒ Object
22 23 24 |
# File 'lib/seaquel/statement_gatherer.rb', line 22 def visit_select parent continue(parent) end |
#visit_set(parent, assign_list) ⇒ Object
49 50 51 52 53 |
# File 'lib/seaquel/statement_gatherer.rb', line 49 def visit_set parent, assign_list continue(parent) s.set.concat(assign_list) end |
#visit_update(parent, table) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/seaquel/statement_gatherer.rb', line 43 def visit_update parent, table continue(parent) s.set_type(:update) s.set_target(table) end |
#visit_values(parent, values) ⇒ Object
79 80 81 82 83 |
# File 'lib/seaquel/statement_gatherer.rb', line 79 def visit_values parent, values continue(parent) s.values << AST::List.new(values) end |
#visit_where(parent, expression) ⇒ Object
37 38 39 40 41 |
# File 'lib/seaquel/statement_gatherer.rb', line 37 def visit_where parent, expression continue(parent) s.where.concat(expression) end |