Sha256: 022bbadadfd874ad5cd50a59a289e4450ad757291e11d0296332029f957ccb32

Contents?: true

Size: 1.03 KB

Versions: 4

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

require "cogger"
require "dry/container"
require "etcher"
require "http"
require "runcom"
require "spek"

module Pennyworth
  # Provides a global gem container for injection into other objects.
  module Container
    extend Dry::Container::Mixin

    register :configuration do
      self[:defaults].add_loader(Etcher::Loaders::YAML.new(self[:xdg_config].active))
                     .then { |registry| Etcher.call registry }
    end

    register :defaults do
      Etcher::Registry.new(contract: Configuration::Contract, model: Configuration::Model)
                      .add_loader(Etcher::Loaders::YAML.new(self[:defaults_path]))
    end

    register(:defaults_path) { Pathname(__dir__).join("configuration/defaults.yml") }
    register(:xdg_config) { Runcom::Config.new "pennyworth/configuration.yml" }
    register(:specification) { Spek::Loader.call "#{__dir__}/../../pennyworth.gemspec" }
    register(:kernel) { Kernel }
    register(:http) { HTTP }
    register(:logger) { Cogger.new formatter: :emoji }
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pennyworth-15.0.3 lib/pennyworth/container.rb
pennyworth-15.0.2 lib/pennyworth/container.rb
pennyworth-15.0.1 lib/pennyworth/container.rb
pennyworth-15.0.0 lib/pennyworth/container.rb