Module: Carb::Inject::AutoInjectable

Defined in:
lib/carb/inject/auto_injectable.rb

Overview

Provides an initializer which sets instance variables with names of dependencies and as value the dependency itself. Requires #inject_dependencies! to be available

Instance Method Summary collapse

Instance Method Details

#initialize(**dependencies) ⇒ Object

Initializes the object with passed dependencies

Parameters:

  • dependencies (Hash)

    map where key is the name of the dependency and value is the actual dependency being injected

Raises:

  • (TypeError)

    raises if doesn’t respond to #inject_dependencies!



12
13
14
15
16
17
18
# File 'lib/carb/inject/auto_injectable.rb', line 12

def initialize(**dependencies)
  unless respond_to?(:inject_dependencies!, true)
    raise TypeError, "#{ self.class } must be injectable"
  end

  inject_dependencies!(**dependencies)
end