Class: Hashira::Analysis::ConstantRegistry
- Inherits:
-
Object
- Object
- Hashira::Analysis::ConstantRegistry
- Defined in:
- lib/hashira/analysis/constant_registry.rb
Constant Summary collapse
- AMBIGUOUS =
Object.new.freeze
Instance Attribute Summary collapse
-
#declaring_package ⇒ Object
readonly
Returns the value of attribute declaring_package.
Instance Method Summary collapse
-
#initialize ⇒ ConstantRegistry
constructor
A new instance of ConstantRegistry.
- #package_for(path) ⇒ Object
- #register(path, package) ⇒ Object
Constructor Details
#initialize ⇒ ConstantRegistry
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_package ⇒ Object (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 |