Class: Solargraph::SourceMap::NodeProcessor::DefNode

Inherits:
Base
  • Object
show all
Defined in:
lib/solargraph/source_map/node_processor/def_node.rb

Direct Known Subclasses

DefsNode

Instance Attribute Summary

Attributes inherited from Base

#locals, #node, #pins, #region

Instance Method Summary collapse

Methods inherited from Base

#initialize

Methods included from Solargraph::Source::NodeMethods

const_from, drill_signature, get_node_end_position, get_node_start_position, infer_literal_node_type, pack_name, resolve_node_signature, returns_from, unpack_name

Constructor Details

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

Instance Method Details

#processObject


5
6
7
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
# File 'lib/solargraph/source_map/node_processor/def_node.rb', line 5

def process
  loc = get_node_location(node)
  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,
    args: method_args,
    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,
      args: 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,
      args: 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,
      args: methpin.parameters,
      node: methpin.node
    )
  else
    pins.push methpin
  end
  process_children region.update(closure: methpin, scope: methpin.scope)
end