Class: Fast::SQL::Node

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

Overview

The SQL node is an AST node with additional tokenization info

Instance Attribute Summary

Attributes inherited from Node

#children, #loc, #type

Instance Method Summary collapse

Methods inherited from Node

#<<, #==, #author, #blame_authors, #buffer_name, #capture, #deconstruct, #each_child_node, #each_descendant, #expression, #file, #from_file?, #git, #git_blob, #git_log, #hash, #initialize, #inspect, #last_commit, #line_range, #lines, #lines_of_code, #link, #location, #md_link, #md_link_description, #method_missing, #parent, parent_for, #permalink, #project_url, #remote_url, #respond_to_missing?, #root?, #search, set_parent, #sha, #source, #to_a, #to_ast, #to_s, #to_sexp, #updated

Constructor Details

This class inherits a constructor from Fast::Node

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Fast::Node

Instance Method Details

#first(pattern) ⇒ Object



85
86
87
# File 'lib/fast/sql.rb', line 85

def first(pattern)
  search(pattern).first
end

#replace(pattern, with = nil, &replacement) ⇒ Object



89
90
91
92
93
94
95
96
# File 'lib/fast/sql.rb', line 89

def replace(pattern, with=nil, &replacement)
  replacement ||= -> (n) { replace(n.loc.expression, with) }
  if root?
    SQL.replace(pattern, self, &replacement)
  else
    parent.replace(pattern, &replacement)
  end
end

#tokenObject



98
99
100
# File 'lib/fast/sql.rb', line 98

def token
  tokens.find{|e|e.start == location.begin}
end

#tokensObject



102
103
104
# File 'lib/fast/sql.rb', line 102

def tokens
  location.expression.source_buffer.tokens
end