Sha256: d73b97a5362514c6af0edee3ad0ebc04148906d2a2141829f5e11c4d6f35c673

Contents?: true

Size: 1.15 KB

Versions: 7

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

require "dry-container"
require "git_plus"
require "logger"
require "pastel"

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

    register(:configuration) { CLI::Configuration::Loader.call }
    register(:colorizer) { Pastel.new enabled: $stdout.tty? }
    register(:kernel) { Kernel }

    register :log_colors do
      {
        "DEBUG" => self[:colorizer].white.detach,
        "INFO" => self[:colorizer].green.detach,
        "WARN" => self[:colorizer].yellow.detach,
        "ERROR" => self[:colorizer].red.detach,
        "FATAL" => self[:colorizer].white.bold.on_red.detach,
        "ANY" => self[:colorizer].white.bold.detach
      }
    end

    register :logger do
      Logger.new $stdout,
                 level: Logger.const_get(ENV.fetch("LOG_LEVEL", "INFO")),
                 formatter: (
                   lambda do |severity, _at, _name, message|
                     self[:log_colors][severity].call "#{message}\n"
                   end
                 )
    end

    register(:repository) { GitPlus::Repository.new }
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
milestoner-12.2.0 lib/milestoner/container.rb
milestoner-12.1.0 lib/milestoner/container.rb
milestoner-12.0.4 lib/milestoner/container.rb
milestoner-12.0.3 lib/milestoner/container.rb
milestoner-12.0.2 lib/milestoner/container.rb
milestoner-12.0.1 lib/milestoner/container.rb
milestoner-12.0.0 lib/milestoner/container.rb