Class: RubyDetective::AST::NodeFactory
- Inherits:
-
Object
- Object
- RubyDetective::AST::NodeFactory
- Defined in:
- lib/ruby_detective/ast/node_factory.rb
Constant Summary collapse
- NODE_TYPE_DICTIONARY =
A dictionary that converts the Parser gem type to our Rich AST type
{ const: :constant, class: :class, module: :module, cbase: :absolute_path_sign }
Instance Attribute Summary collapse
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#parent_node ⇒ Object
readonly
Returns the value of attribute parent_node.
-
#rich_node ⇒ Object
readonly
Returns the value of attribute rich_node.
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(node, file_path:, parent_node: nil) ⇒ NodeFactory
constructor
The following types also exist:.
- #process_all_children ⇒ Object
Constructor Details
#initialize(node, file_path:, parent_node: nil) ⇒ NodeFactory
The following types also exist:
value - the last node of a branch, can be nil, a string, a symbol, etc… generic - a broader “others” type, for any nodes not mapped out
18 19 20 21 22 23 |
# File 'lib/ruby_detective/ast/node_factory.rb', line 18 def initialize(node, file_path:, parent_node: nil) @node = node @rich_node = nil @file_path = file_path @parent_node = parent_node end |
Instance Attribute Details
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
4 5 6 |
# File 'lib/ruby_detective/ast/node_factory.rb', line 4 def file_path @file_path end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
4 5 6 |
# File 'lib/ruby_detective/ast/node_factory.rb', line 4 def node @node end |
#parent_node ⇒ Object (readonly)
Returns the value of attribute parent_node.
4 5 6 |
# File 'lib/ruby_detective/ast/node_factory.rb', line 4 def parent_node @parent_node end |
#rich_node ⇒ Object (readonly)
Returns the value of attribute rich_node.
4 5 6 |
# File 'lib/ruby_detective/ast/node_factory.rb', line 4 def rich_node @rich_node end |
Instance Method Details
#build ⇒ Object
25 26 27 |
# File 'lib/ruby_detective/ast/node_factory.rb', line 25 def build @rich_node = node_class.new(node, file_path: file_path, parent_node: parent_node) end |
#process_all_children ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ruby_detective/ast/node_factory.rb', line 29 def process_all_children rich_node.raw_children.each do |raw_child_node| factory = self.class.new( raw_child_node, file_path: file_path, parent_node: rich_node ) child_node = factory.build rich_node.children << child_node factory.process_all_children end end |