Module: Injectable

Defined in:
lib/injectable.rb,
lib/injectable/macros.rb,
lib/injectable/version.rb,
lib/injectable/registry.rb,
lib/injectable/container.rb,
lib/injectable/inflector.rb,
lib/injectable/registerable.rb

Overview

Objects that include Injectable can have their dependencies satisfied by the container, and removes some basic boilerplate code of creating basic constructors that set instance variables on the class. Constructor injection is the only available option here.

Since:

  • 0.0.0

Defined Under Namespace

Modules: Inflector, Macros, Registerable, Registry Classes: Container

Constant Summary collapse

VERSION =

Since:

  • 0.0.0

"0.0.4"

Class Method Summary collapse

Class Method Details

.configureInjectable::Registry

Configure the global injectable registry. Simply just yields to the registry itself. If no block is provided returns the registry.

Examples:

Configure the registry.

Injectable.configure do |registry|
  registry.register_implementation(:user, User)
end

Returns:

Since:

  • 0.0.3



28
29
30
# File 'lib/injectable.rb', line 28

def configure
  block_given? ? yield(Registry) : Registry
end

.included(klass) ⇒ Object

Including the Injectable module will extend the class with the necessary macros.

Examples:

Include the module.

class UserService
  include Injectable
end

Parameters:

  • klass (Class)

    The including class.

Since:

  • 0.0.0



43
44
45
46
47
48
49
# File 'lib/injectable.rb', line 43

def included(klass)
  Registry.register_implementation(
    Inflector.underscore(klass.name).to_sym,
    klass
  )
  klass.extend(Macros)
end