class Quill::Container
Public Class Methods
new()
click to toggle source
# File lib/quill/container.rb, line 5 def initialize @singletons = {} @factories = {} end
Public Instance Methods
[](name)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/quill/container.rb, line 10 def register_singleton(feature, instance) @singletons[feature] = instance end
Private Instance Methods
instance_from_named_factory(name)
click to toggle source
# File lib/quill/container.rb, line 31 def instance_from_named_factory(name) factory = @factories[name] factory && factory.call(self) end
named_singleton(name)
click to toggle source
# File lib/quill/container.rb, line 27 def named_singleton(name) @singletons[name] end