Class: Dokkit::Environment::Container

Inherits:
Object
  • Object
show all
Defined in:
lib/dokkit/environment/container.rb

Direct Known Subclasses

Basic

Instance Method Summary collapse

Constructor Details

#initializeContainer

Returns a new instance of Container.



14
15
16
17
# File 'lib/dokkit/environment/container.rb', line 14

def initialize
  @registry = { }
  @instances = { }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth) ⇒ Object



19
20
21
# File 'lib/dokkit/environment/container.rb', line 19

def method_missing(meth)
  self[meth]
end

Instance Method Details

#[](service_name) ⇒ Object



23
24
25
# File 'lib/dokkit/environment/container.rb', line 23

def [](service_name)
  @instances[service_name] || (@instances[service_name] = @registry[service_name].call)
end

#register(service_name, &blk) ⇒ Object



27
28
29
30
# File 'lib/dokkit/environment/container.rb', line 27

def register(service_name, &blk)
  @instances[service_name] = nil
  @registry[service_name] = blk
end