Class: Solargraph::Parser::Rubyvm::NodeProcessors::DefsNode

Inherits:
DefNode show all
Includes:
Solargraph::Parser::Rubyvm::NodeMethods
Defined in:
lib/solargraph/parser/rubyvm/node_processors/defs_node.rb

Instance Attribute Summary

Attributes inherited from NodeProcessor::Base

#locals, #node, #pins, #region

Instance Method Summary collapse

Methods included from Solargraph::Parser::Rubyvm::NodeMethods

call_nodes_from, const_nodes_from, convert_hash, find_recipient_node, infer_literal_node_type, node?, pack_name, returns_from, splatted_call?, splatted_hash?, splatted_node?, unpack_name

Methods inherited from NodeProcessor::Base

#initialize

Constructor Details

This class inherits a constructor from Solargraph::Parser::NodeProcessor::Base

Instance Method Details

#processObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/solargraph/parser/rubyvm/node_processors/defs_node.rb', line 10

def process
  s_visi = region.visibility
  s_visi = :public if region.scope != :class
  loc = get_node_location(node)
  if node.children[0].is_a?(RubyVM::AbstractSyntaxTree::Node) && node.children[0].type == :SELF
    closure = region.closure
  else
    closure = Solargraph::Pin::Namespace.new(
      name: unpack_name(node.children[0])
    )
  end
  if s_visi == :module_function
    pins.push Solargraph::Pin::Method.new(
      location: loc,
      closure: closure,
      name: node.children[1].to_s,
      comments: comments_for(node),
      scope: :class,
      visibility: :public,
      node: node
    )
    pins.push Solargraph::Pin::Method.new(
      location: loc,
      closure: closure,
      name: node.children[1].to_s,
      comments: comments_for(node),
      scope: :instance,
      visibility: :private,
      node: node
    )
  else
    pins.push Solargraph::Pin::Method.new(
      location: loc,
      closure: closure,
      name: node.children[1].to_s,
      comments: comments_for(node),
      scope: :class,
      visibility: s_visi,
      node: node
    )
  end
  process_children region.update(closure: pins.last, scope: :class)
end