Class: Hashira::Coupling::ConstantRegistry
- Inherits:
-
Object
- Object
- Hashira::Coupling::ConstantRegistry
- Defined in:
- lib/hashira/coupling/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
- #rooted(path) ⇒ Object
Constructor Details
#initialize ⇒ ConstantRegistry
Returns a new instance of ConstantRegistry.
6 7 8 9 |
# File 'lib/hashira/coupling/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/coupling/constant_registry.rb', line 11 def origins @origins end |
Instance Method Details
#exact(path) ⇒ Object
23 |
# File 'lib/hashira/coupling/constant_registry.rb', line 23 def exact(path) = @origins[path.join("::")] |
#package(path) ⇒ Object
19 |
# File 'lib/hashira/coupling/constant_registry.rb', line 19 def package(path) = settle(anchored(path) || enclosing(path)) |
#packages ⇒ Object
25 |
# File 'lib/hashira/coupling/constant_registry.rb', line 25 def packages = (@origins.values.uniq - [AMBIGUOUS]) |
#register(path, package) ⇒ Object
13 14 15 16 17 |
# File 'lib/hashira/coupling/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 |
#rooted(path) ⇒ Object
21 |
# File 'lib/hashira/coupling/constant_registry.rb', line 21 def rooted(path) = settle(@origins[path.join("::")] || enclosing(path)) |