Class: Veritas::SQL::Generator::Visitor

Inherits:
Object
  • Object
show all
Defined in:
lib/veritas/sql/generator/visitor.rb

Overview

Visit each node in a veritas AST and execute an associated method

Direct Known Subclasses

Relation

Defined Under Namespace

Classes: UnknownObject

Constant Summary collapse

NAME_SEP_REGEXP =
/([a-z])([A-Z])/.freeze
NAME_REP =
'\1_\2'.freeze
DOUBLE_COLON =
'::'.freeze
UNDERSCORE =
'_'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.handler_for(visitable_class) ⇒ #to_sym

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Lookup the handler method for a visitable class

Parameters:

  • visitable_class (Class<Visitable>)

Returns:

  • (#to_sym)

Raises:

  • (UnknownObject)

    raised when the visitable object has no handler



28
29
30
# File 'lib/veritas/sql/generator/visitor.rb', line 28

def self.handler_for(visitable_class)
  handlers[visitable_class] or raise UnknownObject, "No handler for #{visitable_class} in #{self}"
end

Instance Method Details

#visit(visitable) ⇒ self

Visit an object and generate SQL from each node

Examples:

generator.visit(visitable)

Parameters:

  • visitable (Visitable)

Returns:

  • (self)

Raises:

  • (UnknownObject)

    raised when the visitable object has no handler



86
87
88
# File 'lib/veritas/sql/generator/visitor.rb', line 86

def visit(visitable)
  raise NotImplementedError, "#{self.class}#visit must be implemented"
end

#visited?Boolean

Test if a visitable object has been visited

Examples:

visitor.visited?  # true or false

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


98
99
100
# File 'lib/veritas/sql/generator/visitor.rb', line 98

def visited?
  raise NotImplementedError, "#{self.class}#visited? must be implemented"
end