Class: Solargraph::Parser::Legacy::NodeProcessors::DefNode

Inherits:
NodeProcessor::Base show all
Defined in:
lib/solargraph/parser/legacy/node_processors/def_node.rb

Direct Known Subclasses

DefsNode

Instance Attribute Summary

Attributes inherited from NodeProcessor::Base

#locals, #node, #pins, #region

Instance Method Summary collapse

Methods inherited from NodeProcessor::Base

#initialize

Constructor Details

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

Instance Method Details

#processObject



8
9
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
53
54
55
56
57
58
# File 'lib/solargraph/parser/legacy/node_processors/def_node.rb', line 8

def process
  methpin = Solargraph::Pin::Method.new(
    location: get_node_location(node),
    closure: region.closure,
    name: node.children[0].to_s,
    comments: comments_for(node),
    scope: region.scope || (region.closure.is_a?(Pin::Singleton) ? :class : :instance),
    visibility: region.visibility,
    node: node
  )
  if methpin.name == 'initialize' and methpin.scope == :instance
    pins.push Solargraph::Pin::Method.new(
      location: methpin.location,
      closure: methpin.closure,
      name: 'new',
      comments: methpin.comments,
      scope: :class,
      parameters: methpin.parameters
    )
    # @todo Smelly instance variable access.
    pins.last.instance_variable_set(:@return_type, ComplexType::SELF)
    pins.push methpin
    # @todo Smelly instance variable access.
    methpin.instance_variable_set(:@visibility, :private)
    methpin.instance_variable_set(:@return_type, ComplexType::VOID)
  elsif region.visibility == :module_function
    pins.push Solargraph::Pin::Method.new(
      location: methpin.location,
      closure: methpin.closure,
      name: methpin.name,
      comments: methpin.comments,
      scope: :class,
      visibility: :public,
      parameters: methpin.parameters,
      node: methpin.node
    )
    pins.push Solargraph::Pin::Method.new(
      location: methpin.location,
      closure: methpin.closure,
      name: methpin.name,
      comments: methpin.comments,
      scope: :instance,
      visibility: :private,
      parameters: methpin.parameters,
      node: methpin.node
    )
  else
    pins.push methpin
  end
  process_children region.update(closure: methpin, scope: methpin.scope)
end