Class: Manioc::Container
- Inherits:
-
Object
- Object
- Manioc::Container
- Defined in:
- lib/manioc/container.rb
Defined Under Namespace
Classes: DSL
Instance Method Summary collapse
- #clone ⇒ Object
-
#initialize(constructors: {}, &block) ⇒ Container
constructor
A new instance of Container.
- #inspect ⇒ Object
- #preload! ⇒ Object
- #reset!(*keys) ⇒ Object
- #with(constructors = {}, &block) ⇒ Object
Constructor Details
#initialize(constructors: {}, &block) ⇒ Container
Returns a new instance of Container.
21 22 23 24 25 26 27 28 |
# File 'lib/manioc/container.rb', line 21 def initialize constructors: {}, &block @constructors, @cache = constructors, {} @constructors[:env] ||= Manioc::Env.method(:new) register(&block) if block finalize end |
Instance Method Details
#clone ⇒ Object
34 35 36 |
# File 'lib/manioc/container.rb', line 34 def clone with end |
#inspect ⇒ Object
47 48 49 50 51 |
# File 'lib/manioc/container.rb', line 47 def inspect # :nocov: %|<#{self.class.name}(#{@constructors.keys.join(', ')})>| # :nocov: end |
#preload! ⇒ Object
43 44 45 |
# File 'lib/manioc/container.rb', line 43 def preload! @constructors.keys.each { |key| resolve key } end |
#reset!(*keys) ⇒ Object
38 39 40 41 |
# File 'lib/manioc/container.rb', line 38 def reset! *keys keys = @cache.keys if keys.empty? keys.each { |k| @cache.delete k } end |
#with(constructors = {}, &block) ⇒ Object
30 31 32 |
# File 'lib/manioc/container.rb', line 30 def with constructors={}, &block self.class.new constructors: @constructors.merge(constructors), &block end |