Class: Solargraph::Rspec::Walker

Inherits:
Object
  • Object
show all
Defined in:
lib/solargraph/rspec/walker.rb

Defined Under Namespace

Classes: Hook, ParsingError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ast, comments = {}) ⇒ Walker

Returns a new instance of Walker.

Parameters:

  • ast (::Parser::AST::Node)
  • comments (Hash) (defaults to: {})


75
76
77
78
79
# File 'lib/solargraph/rspec/walker.rb', line 75

def initialize(ast, comments = {})
  @comments = comments
  @ast = ast
  @hooks = Hash.new { |h, k| h[k] = [] }
end

Instance Attribute Details

#astObject (readonly)

Returns the value of attribute ast.



71
72
73
# File 'lib/solargraph/rspec/walker.rb', line 71

def ast
  @ast
end

#commentsObject (readonly)

Returns the value of attribute comments.



71
72
73
# File 'lib/solargraph/rspec/walker.rb', line 71

def comments
  @comments
end

Instance Method Details

#on(node_type, args = []) {|, | ... } ⇒ Object

Yield Parameters:

  • (::Parser::AST::Node)
  • (Walker)


83
84
85
# File 'lib/solargraph/rspec/walker.rb', line 83

def on(node_type, args = [], &block)
  @hooks[node_type] << Hook.new(node_type, args, &block)
end

#walkObject



87
88
89
# File 'lib/solargraph/rspec/walker.rb', line 87

def walk
  @ast.is_a?(Array) ? @ast.each { |node| traverse(node) } : traverse(@ast)
end