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

#==, #constant?, #undefined?

Constructor Details

#initialize(word) ⇒ Constant


5
6
7
# File 'lib/solargraph/source/chain/constant.rb', line 5

def initialize word
  @word = word
end

Instance Method Details

#resolve(api_map, name_pin, locals) ⇒ Object


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/solargraph/source/chain/constant.rb', line 9

def resolve api_map, name_pin, locals
  return [Pin::ROOT_PIN] if word.empty?
  if word.start_with?('::')
    context = ''
    bottom = word[2..-1]
  else
    context = name_pin.full_context.namespace
    bottom = word
  end
  if bottom.include?('::')
    ns = bottom.split('::')[0..-2].join('::')
  else
    ns = ''
  end
  result = api_map.get_constants(ns, context)
  last_name = bottom.split('::').last
  result.select{ |p| p.name == last_name }
end