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
-
#origins ⇒ Object
readonly
Returns the value of attribute origins.
Instance Method Summary collapse
- #exact(path) ⇒ Object
-
#initialize ⇒ ConstantRegistry
constructor
A new instance of ConstantRegistry.
- #package(path) ⇒ Object
- #packages ⇒ Object
- #register(path, package) ⇒ Object
Constructor Details
#initialize ⇒ ConstantRegistry
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
#origins ⇒ Object (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 |
#packages ⇒ Object
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 |