Class: Solargraph::Rspec::Walker
- Inherits:
-
Object
- Object
- Solargraph::Rspec::Walker
- Defined in:
- lib/solargraph/rspec/walker.rb
Defined Under Namespace
Classes: Hook
Instance Attribute Summary collapse
-
#ast ⇒ Object
readonly
Returns the value of attribute ast.
-
#comments ⇒ Object
readonly
Returns the value of attribute comments.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(ast, comments = {}) ⇒ Walker
constructor
A new instance of Walker.
- #on(node_type, args = [], &block) ⇒ Object
- #walk ⇒ void
Constructor Details
#initialize(ast, comments = {}) ⇒ Walker
Returns a new instance of Walker.
90 91 92 93 94 |
# File 'lib/solargraph/rspec/walker.rb', line 90 def initialize(ast, comments = {}) @comments = comments @ast = ast @hooks = Hash.new([]) end |
Instance Attribute Details
#ast ⇒ Object (readonly)
Returns the value of attribute ast.
84 85 86 |
# File 'lib/solargraph/rspec/walker.rb', line 84 def ast @ast end |
#comments ⇒ Object (readonly)
Returns the value of attribute comments.
86 87 88 |
# File 'lib/solargraph/rspec/walker.rb', line 86 def comments @comments end |
Class Method Details
.from_source(source) ⇒ Object
79 80 81 |
# File 'lib/solargraph/rspec/walker.rb', line 79 def self.from_source(source) new(*normalize_ast(source)) end |
.normalize_ast(source) ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/solargraph/rspec/walker.rb', line 68 def self.normalize_ast(source) ast = source.node if ast.is_a?(::Parser::AST::Node) ast else NodeParser.parse_with_comments(source.code, source.filename) end end |
Instance Method Details
#on(node_type, args = [], &block) ⇒ Object
99 100 101 |
# File 'lib/solargraph/rspec/walker.rb', line 99 def on(node_type, args = [], &block) @hooks[node_type] << Hook.new(node_type, args, &block) end |
#walk ⇒ void
This method returns an undefined value.
104 105 106 |
# File 'lib/solargraph/rspec/walker.rb', line 104 def walk @ast.is_a?(Array) ? @ast.each { |node| traverse(node) } : traverse(@ast) end |