Class: Liveness::Container

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

Overview

The dependency provider container

Since:

  • 0.1.0

Instance Method Summary collapse

Constructor Details

#initializeLiveness::Container

Since:

  • 0.1.0



11
12
13
# File 'lib/liveness/container.rb', line 11

def initialize
  @dependencies = {}
end

Instance Method Details

#create(name, **options, &block) ⇒ Liveness::Dependency|NilClass

Create a dependency

Parameters:

  • name (Symbol)

    the dependency name

  • block (Proc)

    the block to configure dependency

Returns:

Since:

  • 0.1.0



33
34
35
36
37
38
39
# File 'lib/liveness/container.rb', line 33

def create(name, **options, &block)
  klass = @dependencies[name.to_sym]
  return if klass.nil?

  options[:name] ||= name
  klass.new(**options, &block)
end

#register(name, klass) ⇒ Object

Register new dependency type

Parameters:

  • name (Symbol)

    the dependency name

  • klass (Class)

    the class to register

Since:

  • 0.1.0



21
22
23
# File 'lib/liveness/container.rb', line 21

def register(name, klass)
  @dependencies[name.to_sym] = klass
end