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 (RubyVM::AbstractSyntaxTree::Node)
  • comments (Hash) (defaults to: {})


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

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

Instance Attribute Details

#astObject (readonly)

Returns the value of attribute ast.



67
68
69
# File 'lib/solargraph/rspec/walker.rb', line 67

def ast
  @ast
end

#commentsObject (readonly)

Returns the value of attribute comments.



67
68
69
# File 'lib/solargraph/rspec/walker.rb', line 67

def comments
  @comments
end

Instance Method Details

#on(node_type, args = [], &block) ⇒ Object



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

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

#walkObject



81
82
83
# File 'lib/solargraph/rspec/walker.rb', line 81

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