Class: Solargraph::Parser::Legacy::NodeChainer

Inherits:
Object
  • Object
show all
Includes:
NodeMethods
Defined in:
lib/solargraph/parser/legacy/node_chainer.rb

Overview

A factory for generating chains from nodes.

Constant Summary collapse

Chain =
Source::Chain

Constants included from NodeMethods

Solargraph::Parser::Legacy::NodeMethods::NIL_NODE

Class Method Summary collapse

Instance Method Summary collapse

Methods included from NodeMethods

any_splatted_call?, call_nodes_from, const_nodes_from, convert_hash, drill_signature, find_recipient_node, get_node_end_position, get_node_start_position, infer_literal_node_type, pack_name, repaired_find_recipient_node, returns_from, splatted_call?, splatted_hash?, unpack_name

Constructor Details

#initialize(node, filename = nil, in_block = false) ⇒ NodeChainer

Returns a new instance of NodeChainer.

Parameters:

  • node (Parser::AST::Node)
  • filename (String) (defaults to: nil)


14
15
16
17
18
# File 'lib/solargraph/parser/legacy/node_chainer.rb', line 14

def initialize node, filename = nil, in_block = false
  @node = node
  @filename = filename
  @in_block = in_block ? 1 : 0
end

Class Method Details

.chain(node, filename = nil, in_block = false) ⇒ Source::Chain

Parameters:

  • node (Parser::AST::Node)
  • filename (String) (defaults to: nil)

Returns:



30
31
32
# File 'lib/solargraph/parser/legacy/node_chainer.rb', line 30

def chain node, filename = nil, in_block = false
  NodeChainer.new(node, filename, in_block).chain
end

.load_string(code) ⇒ Source::Chain

Parameters:

  • code (String)

Returns:



36
37
38
39
40
41
# File 'lib/solargraph/parser/legacy/node_chainer.rb', line 36

def load_string(code)
  node = Parser.parse(code.sub(/\.$/, ''))
  chain = NodeChainer.new(node).chain
  chain.links.push(Chain::Link.new) if code.end_with?('.')
  chain
end

Instance Method Details

#chainSource::Chain

Returns:



21
22
23
24
# File 'lib/solargraph/parser/legacy/node_chainer.rb', line 21

def chain
  links = generate_links(@node)
  Chain.new(links, @node, (Parser.is_ast_node?(@node) && @node.type == :splat))
end