Class: Imagen::Visitor
- Inherits:
-
Object
- Object
- Imagen::Visitor
- Defined in:
- lib/imagen/visitor.rb
Overview
AST Traversal that calls respective builder methods from Imagen::Node
Constant Summary collapse
- TYPES =
{ block: Imagen::Node::Block, class: Imagen::Node::Class, def: Imagen::Node::IMethod, defs: Imagen::Node::CMethod, module: Imagen::Node::Module }.freeze
Instance Attribute Summary collapse
-
#current_root ⇒ Object
readonly
Returns the value of attribute current_root.
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Class Method Summary collapse
Instance Method Summary collapse
- #traverse(ast_node, parent) ⇒ Object
-
#visit(ast_node, parent) ⇒ Object
This method reeks of :reek:UtilityFunction.
Instance Attribute Details
#current_root ⇒ Object (readonly)
Returns the value of attribute current_root.
14 15 16 |
# File 'lib/imagen/visitor.rb', line 14 def current_root @current_root end |
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
14 15 16 |
# File 'lib/imagen/visitor.rb', line 14 def file_path @file_path end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
14 15 16 |
# File 'lib/imagen/visitor.rb', line 14 def root @root end |
Class Method Details
Instance Method Details
#traverse(ast_node, parent) ⇒ Object
21 22 23 24 25 |
# 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) ⇒ Object
This method reeks of :reek:UtilityFunction
28 29 30 31 32 33 |
# File 'lib/imagen/visitor.rb', line 28 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 |