Class: Jerry

Inherits:
Object
  • Object
show all
Defined in:
lib/jerry.rb,
lib/jerry/config.rb,
lib/jerry/errors.rb,
lib/jerry/version.rb,
lib/jerry/class_provider.rb

Overview

Inversion of Control container.

This class is in charge of bootstrapping your application. This is done by defining configs.

Examples:

Basic usage

class FooConfig < Jerry::Config
  # ...
end

class BarConfig < Jerry::Config
  # ...
end

jerry = Jerry.new FooConfig.new, BarConfig.new
jerry[SomeClass] #=> #<Someclass:...>

Defined Under Namespace

Classes: ClassProvider, Config, Error, InstantiationError

Constant Summary collapse

VERSION =
'2.0.1'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(*configs) ⇒ Jerry

Returns a new instance of Jerry.

Parameters:

  • configs (Array<Jerry::Config>)

    configurations describing how to wire your application



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

def initialize(*configs)
  configs.each { |conf| conf.jerry = self }

  @configs = configs
end

Instance Method Details

#[](key) ⇒ Object

Returns an insance of the sepcified key provided by one of the configs.

Parameters:

  • key

    what to provide

Returns:

  • an insance of the sepcified key provided by one of the configs

Raises:



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

def [](key)
  config = @configs.find { |conf| conf.knows? key }
  unless config
    raise Jerry::InstantiationError, "Can't find #{key} in any config"
  end

  config[key]
end