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.



8
9
10
11
# File 'lib/hashira/analysis/constant_registry.rb', line 8

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

Instance Attribute Details

#declaring_packageObject (readonly)

Returns the value of attribute declaring_package.



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

def declaring_package
  @declaring_package
end

Instance Method Details

#package_for(path) ⇒ Object



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

def package_for(path)
  found = path.length.downto(1).filter_map { claimed(path.first(it)) }.first
  found unless found == AMBIGUOUS
end

#register(path, package) ⇒ Object



15
16
17
18
19
20
# File 'lib/hashira/analysis/constant_registry.rb', line 15

def register(path, package)
  return if path.empty?

  claim(@declaring_package, path, package)
  (1...path.length).each { claim(@shorthand, path.drop(it), package) }
end