Module: SimpleCov::Formatter::AIFormatter::ASTResolver::NodeChildren

Extended by:
T::Sig
Defined in:
lib/simplecov-ai/ast_resolver/node_children.rb

Overview

Typed access to the children of Parser AST nodes. Parser types every child as untyped while each node type the resolver reads has one known shape (:def holds its name Symbol first, :casgn its scope node, name Symbol and value node), so the casts live here and every call site names the child it reads and nothing else.

Class Method Summary collapse

Class Method Details

.literal_value(node) ⇒ Object



49
50
51
# File 'lib/simplecov-ai/ast_resolver/node_children.rb', line 49

def self.literal_value(node)
  T.cast(node.children[0], T.any(Symbol, String)).to_s
end

.node_at(node, index) ⇒ Object



19
20
21
# File 'lib/simplecov-ai/ast_resolver/node_children.rb', line 19

def self.node_at(node, index)
  T.cast(node.children[index], T.nilable(Parser::AST::Node))
end

.required_node_at(node, index) ⇒ Object



27
28
29
# File 'lib/simplecov-ai/ast_resolver/node_children.rb', line 27

def self.required_node_at(node, index)
  T.cast(node.children[index], Parser::AST::Node)
end

.symbol_at(node, index) ⇒ Object



35
36
37
# File 'lib/simplecov-ai/ast_resolver/node_children.rb', line 35

def self.symbol_at(node, index)
  T.cast(node.children[index], Symbol)
end

.variable_name(node) ⇒ Object



42
43
44
# File 'lib/simplecov-ai/ast_resolver/node_children.rb', line 42

def self.variable_name(node)
  T.cast(node.children[0], Symbol)
end