class Imagen::Visitor

AST Traversal that calls respective builder methods from Imagen::Node

Constants

TYPES

Attributes

current_root[R]
file_path[R]
root[R]

Public Class Methods

traverse(ast, root) click to toggle source
# File lib/imagen/visitor.rb, line 16
def self.traverse(ast, root)
  new.traverse(ast, root)
  root
end

Public Instance Methods

traverse(ast_node, parent) click to toggle source
# File lib/imagen/visitor.rb, line 21
def traverse(ast_node, parent)
  return unless ast_node.is_a?(Parser::AST::Node)

  node = visit(ast_node, parent)
  ast_node.children.each { |child| traverse(child, node || parent) }
end
visit(ast_node, parent) click to toggle source

This method reeks of :reek:UtilityFunction

# File lib/imagen/visitor.rb, line 29
def visit(ast_node, parent)
  klass = TYPES[ast_node.type] || return
  klass.new.build_from_ast(ast_node).tap do |node|
    parent.children << node
  end
end