Sha256: 54c210c90f0c46f06bc1a98b0001c098602093212d801b1a6fde63427d46f874

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

require 'jerry/version'
require 'jerry/errors'
require 'jerry/config'

# Inversion of Control container.
#
# This class is in charge of bootstrapping your application. This is done by
# defining {Jerry::Config configs}.
#
# @example Basic usage
#   class FooConfig < Jerry::Config
#     # ...
#   end
#
#   class BarConfig < Jerry::Config
#     # ...
#   end
#
#   jerry = Jerry.new FooConfig.new, BarConfig.new
#   jerry[SomeClass] #=> #<Someclass:...>
class Jerry
  # @param configs [Array<Jerry::Config>] configurations describing how to wire
  #   your application
  def initialize(*configs)
    configs.each { |conf| conf.jerry = self }

    @configs = configs
  end

  # @param key what to provide
  # @return an insance of the sepcified key provided by one of the configs
  # @raise [Jerry::InstantiationError] if can't instanciate key
  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
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jerry-2.0.1 lib/jerry.rb