Class: Spektr::Processors::Base
- Inherits:
-
Object
- Object
- Spektr::Processors::Base
- Includes:
- AST::Processor::Mixin
- Defined in:
- lib/spektr/processors/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#name_parts ⇒ Object
Returns the value of attribute name_parts.
-
#parent_modules ⇒ Object
Returns the value of attribute parent_modules.
-
#parent_name ⇒ Object
Returns the value of attribute parent_name.
-
#parent_name_with_modules ⇒ Object
Returns the value of attribute parent_name_with_modules.
-
#parent_parts ⇒ Object
Returns the value of attribute parent_parts.
Instance Method Summary collapse
- #extract_name_part(node) ⇒ Object
- #extract_parent_parts(node) ⇒ Object
- #handler_missing(node) ⇒ Object
-
#initialize ⇒ Base
constructor
A new instance of Base.
- #on_begin(node) ⇒ Object
- #on_class(node) ⇒ Object
- #on_const(node) ⇒ Object
- #on_module(node) ⇒ Object
- #part_matches_self?(part) ⇒ Boolean
- #part_with_module(part) ⇒ Object
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
7 8 9 10 11 12 |
# File 'lib/spektr/processors/base.rb', line 7 def initialize @modules = [] @name_parts = [] @parent_parts = [] @parent_modules = [] end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/spektr/processors/base.rb', line 5 def name @name end |
#name_parts ⇒ Object
Returns the value of attribute name_parts.
5 6 7 |
# File 'lib/spektr/processors/base.rb', line 5 def name_parts @name_parts end |
#parent_modules ⇒ Object
Returns the value of attribute parent_modules.
5 6 7 |
# File 'lib/spektr/processors/base.rb', line 5 def parent_modules @parent_modules end |
#parent_name ⇒ Object
Returns the value of attribute parent_name.
5 6 7 |
# File 'lib/spektr/processors/base.rb', line 5 def parent_name @parent_name end |
#parent_name_with_modules ⇒ Object
Returns the value of attribute parent_name_with_modules.
5 6 7 |
# File 'lib/spektr/processors/base.rb', line 5 def parent_name_with_modules @parent_name_with_modules end |
#parent_parts ⇒ Object
Returns the value of attribute parent_parts.
5 6 7 |
# File 'lib/spektr/processors/base.rb', line 5 def parent_parts @parent_parts end |
Instance Method Details
#extract_name_part(node) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/spektr/processors/base.rb', line 69 def extract_name_part(node) parts = [] node.children.first.children.each do |child| if child.is_a?(Parser::AST::Node) parts << child.children.last elsif child.is_a? Symbol parts << child.to_s end end parts end |
#extract_parent_parts(node) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/spektr/processors/base.rb', line 53 def extract_parent_parts(node) return unless node.is_a?(Parser::AST::Node) && %i[ module class const send].include?(node.type) @parent_parts.prepend(node.children.last) if node.type == :const if node.children.any? node.children.each do |child| extract_parent_parts(child) end end end |
#handler_missing(node) ⇒ Object
83 84 85 |
# File 'lib/spektr/processors/base.rb', line 83 def handler_missing(node) # puts "handler missing for #{node.type}" end |
#on_begin(node) ⇒ Object
41 42 43 |
# File 'lib/spektr/processors/base.rb', line 41 def on_begin(node) process_all(node) end |
#on_class(node) ⇒ Object
63 64 65 66 67 |
# File 'lib/spektr/processors/base.rb', line 63 def on_class(node) extract_parent_parts(node) @name_parts.concat(extract_name_part(node)) process_all(node) end |
#on_const(node) ⇒ Object
81 |
# File 'lib/spektr/processors/base.rb', line 81 def on_const(node); end |
#on_module(node) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/spektr/processors/base.rb', line 45 def on_module(node) parts = extract_name_part(node) @modules.concat(parts) @name_parts.concat(parts) @parent_modules << node.children.first.children.last process_all(node) end |
#part_matches_self?(part) ⇒ Boolean
28 29 30 |
# File 'lib/spektr/processors/base.rb', line 28 def part_matches_self?(part) (part == name || part_with_module(part) == name) end |
#part_with_module(part) ⇒ Object
32 33 34 |
# File 'lib/spektr/processors/base.rb', line 32 def part_with_module(part) (@parent_modules | [part]).join('::') end |