Sha256: d4d903a1c20c779b1d39b119d85f9b06f1dc54430fc24bb92f92e52ac9c7654e

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

require "cogger"
require "dry-container"
require "etcher"
require "runcom"
require "spek"

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

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

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

    register :specification, memoize: true do
      Spek::Loader.call "#{__dir__}/../../pragmater.gemspec"
    end

    register(:input, memoize: true) { self[:configuration].dup }
    register(:defaults_path, memoize: true) { Pathname(__dir__).join("configuration/defaults.yml") }
    register(:xdg_config, memoize: true) { Runcom::Config.new "pragmater/configuration.yml" }
    register(:logger, memoize: true) { Cogger.new formatter: :emoji }
    register :kernel, Kernel
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pragmater-13.1.0 lib/pragmater/container.rb