Module: Injectable::Registry

Extended by:
Registry
Includes:
Registerable
Included in:
Registry
Defined in:
lib/injectable/registry.rb

Overview

The registry keeps track of all objects and their dependencies that need to be injected at construction.

Since:

  • 0.0.0

Defined Under Namespace

Classes: NotRegistered

Instance Method Summary collapse

Methods included from Registerable

#register_implementation

Instance Method Details

#implementation(name) ⇒ Class

Get an implementation for the provided name.

Examples:

Get an implementation.

Injectable::Registry.implementation(:persistable)

Parameters:

  • name (Symbol)

    The name of the implementation.

Returns:

  • (Class)

    The implementing class.

Raises:

Since:

  • 0.0.2



24
25
26
27
28
# File 'lib/injectable/registry.rb', line 24

def implementation(name)
  impl = implementations[name]
  raise(NotRegistered.new(name)) unless impl && !impl.empty?
  impl
end

#register_signature(klass, dependencies) ⇒ Object

Add a constructor method signature to the registry.

Examples:

Add a signature.

Injectable::Registry.register_signature(
  UserService, [ :user, :user_finder ]
)

Parameters:

  • klass (Class)

    The class to set the constructor signature for.

  • dependencies (Array<Symbol>)

    The dependencies of the constructor.

Since:

  • 0.0.0



42
43
44
# File 'lib/injectable/registry.rb', line 42

def register_signature(klass, dependencies)
  signatures[klass] = dependencies.map { |name| name }
end

#signature(klass) ⇒ Array<Class>

Get the constructor method signature for the provided class.

Examples:

Get the constructor signature.

Injectable::Registry.signature(UserService)

Parameters:

  • klass (Class)

    The class to get the signature for.

Returns:

  • (Array<Class>)

    The constructor signature.

Since:

  • 0.0.0



56
57
58
# File 'lib/injectable/registry.rb', line 56

def signature(klass)
  signatures[klass]
end