Class: SqlTools::PredicateVisitor

Inherits:
TreeStand::Visitor
  • Object
show all
Defined in:
lib/sql_tools/predicate_visitor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#stackObject (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)