Class: Fast::SQL::Rewriter

Inherits:
Rewriter
  • Object
show all
Defined in:
lib/fast/sql/rewriter.rb

Overview

Extends fast rewriter to support SQL

See Also:

Instance Attribute Summary

Attributes inherited from Rewriter

#ast, #match_index, #replacement, #search, #source

Instance Method Summary collapse

Methods inherited from Rewriter

#buffer, #execute_replacement, #initialize, #match?, #rewrite!

Constructor Details

This class inherits a constructor from Fast::Rewriter

Instance Method Details

#replace_on(*types) ⇒ Object

Generate methods for all affected types. Note the strategy is different from parent class, it if matches the root node, it executes otherwise it search pattern on all matching elements.

See Also:



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/fast/sql/rewriter.rb', line 53

def replace_on(*types)
  types.map do |type|
    self.instance_exec do
      self.class.define_method :"on_#{ast.type}" do |node|
        # SQL nodes are not being automatically invoked by the rewriter,
        # so we need to match the root node and invoke on matching inner elements.
        node.search(search).each_with_index do |node, i|
          @match_index += 1
          execute_replacement(node, nil)
        end
      end
    end
  end
end

#typesArray<Symbol>

Returns with all types that matches.

Returns:

  • (Array<Symbol>)

    with all types that matches



45
46
47
# File 'lib/fast/sql/rewriter.rb', line 45

def types
  ast.type
end