Class: Solargraph::Source::Chain::Constant

Inherits:
Link
  • Object
show all
Defined in:
lib/solargraph/source/chain/constant.rb

Instance Attribute Summary

Attributes inherited from Link

#last_context, #word

Instance Method Summary collapse

Methods inherited from Link

#==, #clone_body, #clone_head, #constant?, #head?, #undefined?

Constructor Details

#initialize(word) ⇒ Constant

Returns a new instance of Constant.



7
8
9
# File 'lib/solargraph/source/chain/constant.rb', line 7

def initialize word
  @word = word
end

Instance Method Details

#resolve(api_map, name_pin, locals) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/solargraph/source/chain/constant.rb', line 11

def resolve api_map, name_pin, locals
  return [Pin::ROOT_PIN] if word.empty?
  if word.start_with?('::')
    base = word[2..-1]
    gates = ['']
  else
    base = word
    gates = crawl_gates(name_pin)
  end
  parts = base.split('::')
  gates.each do |gate|
    type = deep_constant_type(gate, api_map)
    # Use deep inference to resolve root 
    parts[0..-2].each do |sym|
      pins = api_map.get_constants('', type.namespace).select{ |pin| pin.name == sym }
      type = first_pin_type(pins, api_map)
      break if type.undefined?
    end
    next if type.undefined?
    result = api_map.get_constants('', type.namespace).select { |pin| pin.name == parts.last }
    return result unless result.empty?
  end
  []
end