class Hypo::Lifetime::Singleton

Public Class Methods

new() click to toggle source
# File lib/hypo/lifetime/singleton.rb, line 4
def initialize
  @instances = Hash.new
  @mutex = Mutex.new
end

Public Instance Methods

instance(component, attrs = nil) click to toggle source
# File lib/hypo/lifetime/singleton.rb, line 9
def instance(component, attrs = nil)
  @instances[component.name]
end
preload(component) click to toggle source
# File lib/hypo/lifetime/singleton.rb, line 13
def preload(component)
  @mutex.synchronize do
    unless @instances.key? component.name
      instance = component.respond_to?(:type) ? component.type.new(*component.dependencies) : component.object
      @instances[component.name] = instance
    end
  end
end