Sha256: 3d2110663ffdf279278f7d0262051f56f433f65dd0a24807a5b05ae34b9a8027

Contents?: true

Size: 1.09 KB

Versions: 5

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

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

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

    register(:configuration, memoize: true) { 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
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rubysmith-0.16.1 lib/rubysmith/container.rb
rubysmith-0.16.0 lib/rubysmith/container.rb
rubysmith-0.15.0 lib/rubysmith/container.rb
rubysmith-0.14.0 lib/rubysmith/container.rb
rubysmith-0.13.0 lib/rubysmith/container.rb