class Manioc::Container
Public Class Methods
new(constructors: {})
click to toggle source
# 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
Public Instance Methods
clone()
click to toggle source
# File lib/manioc/container.rb, line 34 def clone with end
inspect()
click to toggle source
# File lib/manioc/container.rb, line 47 def inspect # :nocov: %|<#{self.class.name}(#{@constructors.keys.join(', ')})>| # :nocov: end
preload!()
click to toggle source
# File lib/manioc/container.rb, line 43 def preload! @constructors.keys.each { |key| resolve key } end
reset!(*keys)
click to toggle source
# 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={})
click to toggle source
# File lib/manioc/container.rb, line 30 def with constructors={}, &block self.class.new constructors: @constructors.merge(constructors), &block end
Private Instance Methods
finalize()
click to toggle source
# File lib/manioc/container.rb, line 63 def finalize @constructors.freeze @constructors.keys.each do |key| define_singleton_method(key) { resolve key } end end
register(&block)
click to toggle source
# File lib/manioc/container.rb, line 55 def register &block @constructors.merge! DSL.new(&block).to_h end
resolve(key)
click to toggle source
# File lib/manioc/container.rb, line 59 def resolve key @cache[key] ||= instance_exec(&@constructors[key]) end