Class: Solargraph::Rspec::SpecWalker::FullConstantName

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

Class Method Summary collapse

Class Method Details

.from_ast(ast) ⇒ String

Parameters:

  • ast (RubyVM::AbstractSyntaxTree::Node)

Returns:

  • (String)


10
11
12
13
14
15
16
17
18
19
# File 'lib/solargraph/rspec/spec_walker/full_constant_name.rb', line 10

def from_ast(ast)
  raise 'Node is not a constant' unless NodeTypes.a_constant?(ast)

  if ast.type == :CONST
    ast.children[0].to_s
  elsif ast.type == :COLON2
    name = ast.children[1].to_s
    "#{from_ast(ast.children[0])}::#{name}"
  end
end

.from_context_block_ast(block_ast) ⇒ Object



21
22
23
24
# File 'lib/solargraph/rspec/spec_walker/full_constant_name.rb', line 21

def from_context_block_ast(block_ast)
  ast = NodeTypes.context_description_node(block_ast)
  from_ast(ast)
end