Sha256: 5950350deb5ea03cd0ff3d234378a5d9b1e1b6a1c50d045e5e105d858a40e79b

Contents?: true

Size: 1.05 KB

Versions: 2

Compression:

Stored size: 1.05 KB

Contents

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

<% namespace do %>
  # Provides a global gem container for injection into other objects.
  module Container
    extend Dry::Container::Mixin

    register(:configuration) { 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

2 entries across 2 versions & 1 rubygems

Version Path
gemsmith-16.1.0 lib/gemsmith/templates/%project_name%/lib/%project_path%/container.rb.erb
gemsmith-16.0.0 lib/gemsmith/templates/%project_name%/lib/%project_path%/container.rb.erb