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

#word

Instance Method Summary collapse

Methods inherited from Link

#==, #constant?, #undefined?

Constructor Details

#initialize(word) ⇒ Constant

Returns a new instance of 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
# 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.context.namespace
    bottom = word
  end
  if bottom.include?('::')
    ns = bottom.split('::')[0..-2].join('::')
  else
    ns = ''
  end
  api_map.get_constants(ns, context).select{|p| p.path.end_with?(bottom)}
end