Class: Quill::Container
- Inherits:
-
Object
- Object
- Quill::Container
- Defined in:
- lib/quill/container.rb
Instance Method Summary collapse
- #[](name) ⇒ Object
-
#initialize ⇒ Container
constructor
A new instance of Container.
- #register_class(klass) ⇒ Object
- #register_singleton(feature, instance) ⇒ Object
Constructor Details
#initialize ⇒ Container
Returns a new instance of Container.
5 6 7 8 |
# File 'lib/quill/container.rb', line 5 def initialize @singletons = {} @factories = {} end |
Instance Method Details
#[](name) ⇒ Object
20 21 22 23 |
# File 'lib/quill/container.rb', line 20 def [](name) instance = named_singleton(name) || instance_from_named_factory(name) instance or raise UnsatisfiedDependencyError.new(name) end |
#register_class(klass) ⇒ Object
14 15 16 17 18 |
# File 'lib/quill/container.rb', line 14 def register_class(klass) raise NoFactoryError.new(klass) unless klass.respond_to?(:factory) factory = klass.factory @factories[factory.feature] = factory end |
#register_singleton(feature, instance) ⇒ Object
10 11 12 |
# File 'lib/quill/container.rb', line 10 def register_singleton(feature, instance) @singletons[feature] = instance end |