Class: Aux::Registry
- Inherits:
-
Object
- Object
- Aux::Registry
- Defined in:
- lib/aux/registry.rb,
lib/aux/registry/entry.rb
Overview
Registry for dependency injection
Instance Method Summary collapse
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
- #key?(key) ⇒ TrueClass, FalseClass
- #register(key, memoize: false, &constructor) ⇒ Object
- #resolve(key) ⇒ Object
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
9 10 11 |
# File 'lib/aux/registry.rb', line 9 def initialize @prototypes = ::Concurrent::Map.new end |
Instance Method Details
#key?(key) ⇒ TrueClass, FalseClass
28 29 30 |
# File 'lib/aux/registry.rb', line 28 def key?(key) @prototypes.key?(key.to_s) end |
#register(key, memoize: false, &constructor) ⇒ Object
16 17 18 |
# File 'lib/aux/registry.rb', line 16 def register(key, memoize: false, &constructor) @prototypes.put(key.to_s, Entry.new(constructor, memoize)) end |
#resolve(key) ⇒ Object
22 23 24 |
# File 'lib/aux/registry.rb', line 22 def resolve(key) @prototypes.fetch(key.to_s).call end |