Class: SqlTools::PredicateVisitor
- Inherits:
-
TreeStand::Visitor
- Object
- TreeStand::Visitor
- SqlTools::PredicateVisitor
- Defined in:
- lib/sql_tools/predicate_visitor.rb
Instance Attribute Summary collapse
-
#stack ⇒ Object
readonly
Returns the value of attribute stack.
Instance Method Summary collapse
- #around_binary_expression(node) ⇒ Object
-
#initialize(node) ⇒ PredicateVisitor
constructor
A new instance of PredicateVisitor.
- #on_field(node) ⇒ Object
- #on_literal(node) ⇒ Object
Constructor Details
#initialize(node) ⇒ PredicateVisitor
Returns a new instance of PredicateVisitor.
4 5 6 7 |
# File 'lib/sql_tools/predicate_visitor.rb', line 4 def initialize(node) super(node) @stack = [] end |
Instance Attribute Details
#stack ⇒ Object (readonly)
Returns the value of attribute stack.
3 4 5 |
# File 'lib/sql_tools/predicate_visitor.rb', line 3 def stack @stack end |
Instance Method Details
#around_binary_expression(node) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/sql_tools/predicate_visitor.rb', line 9 def around_binary_expression(node) @stack << Predicate::Binary.new(nil, node.operator.text, nil) yield @stack[-3].right = @stack.pop @stack[-2].left = @stack.pop end |
#on_field(node) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/sql_tools/predicate_visitor.rb', line 16 def on_field(node) parent = node.parent # Case JOIN ON v.is_not_deleted @stack << node if parent.type == :join || parent.type == :where # Case JOIN ON _ AND v.is_not_deleted @stack << node if parent.type == :binary_expression end |
#on_literal(node) ⇒ Object
24 |
# File 'lib/sql_tools/predicate_visitor.rb', line 24 def on_literal(node) = on_field(node) |