Class: Hashira::Analysis::ConstantRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/hashira/analysis/constant_registry.rb

Constant Summary collapse

AMBIGUOUS =
Object.new.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConstantRegistry

Returns a new instance of ConstantRegistry.



6
7
8
9
# File 'lib/hashira/analysis/constant_registry.rb', line 6

def initialize
  @origins = {}
  @shorthand = {}
end

Instance Attribute Details

#originsObject (readonly)

Returns the value of attribute origins.



11
12
13
# File 'lib/hashira/analysis/constant_registry.rb', line 11

def origins
  @origins
end

Instance Method Details

#exact(path) ⇒ Object



24
# File 'lib/hashira/analysis/constant_registry.rb', line 24

def exact(path) = @origins[path.join("::")]

#package(path) ⇒ Object



19
20
21
22
# File 'lib/hashira/analysis/constant_registry.rb', line 19

def package(path)
  found = anchored(path) || enclosing(path)
  found unless found == AMBIGUOUS
end

#packagesObject



26
# File 'lib/hashira/analysis/constant_registry.rb', line 26

def packages = (@origins.values.uniq - [AMBIGUOUS])

#register(path, package) ⇒ Object



13
14
15
16
17
# File 'lib/hashira/analysis/constant_registry.rb', line 13

def register(path, package)
  return if path.empty?
  claim(@origins, path, package)
  (1...path.length).each { claim(@shorthand, path.drop(it), package) }
end