Sha256: 089f9cd40b065a85d7f24d226f6bad4271a7c0434a4f6a57b8e7bec0741dcef3

Contents?: true

Size: 1.43 KB

Versions: 19

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

require "pathname"
require "refinements/arrays"
require "refinements/hashes"
require "refinements/structs"
require "runcom"
require "yaml"

module Gemsmith
  module Configuration
    # Represents the fully assembled Command Line Interface (CLI) configuration.
    class Loader
      using Refinements::Arrays
      using Refinements::Hashes
      using Refinements::Structs

      DEFAULTS = Rubysmith::Configuration::Loader::DEFAULTS
      CLIENT = Runcom::Config.new "gemsmith/configuration.yml", defaults: DEFAULTS

      ENHANCERS = Rubysmith::Configuration::Loader::ENHANCERS.including(Enhancers::TemplateRoot.new)
                                                             .freeze

      def self.call(...) = new(...).call

      def self.with_defaults = new(client: DEFAULTS, enhancers: [])

      def self.with_overrides = new(client: DEFAULTS, enhancers: [Enhancers::TemplateRoot.new])

      def initialize content: Rubysmith::Configuration::Content.new,
                     client: CLIENT,
                     enhancers: ENHANCERS
        @content = content
        @client = client
        @enhancers = enhancers
      end

      def call
        enhancers.reduce(preload_content) { |preload, enhancer| enhancer.call preload }
                 .freeze
      end

      private

      attr_reader :content, :client, :enhancers

      def preload_content = content.merge(**client.to_h.flatten_keys)
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
gemsmith-19.0.0 lib/gemsmith/configuration/loader.rb
gemsmith-18.9.0 lib/gemsmith/configuration/loader.rb
gemsmith-18.8.0 lib/gemsmith/configuration/loader.rb
gemsmith-18.7.0 lib/gemsmith/configuration/loader.rb
gemsmith-18.6.0 lib/gemsmith/configuration/loader.rb
gemsmith-18.5.0 lib/gemsmith/configuration/loader.rb
gemsmith-18.4.0 lib/gemsmith/configuration/loader.rb
gemsmith-18.3.0 lib/gemsmith/configuration/loader.rb
gemsmith-18.2.0 lib/gemsmith/configuration/loader.rb
gemsmith-18.1.1 lib/gemsmith/configuration/loader.rb
gemsmith-18.1.0 lib/gemsmith/configuration/loader.rb
gemsmith-18.0.2 lib/gemsmith/configuration/loader.rb
gemsmith-18.0.1 lib/gemsmith/configuration/loader.rb
gemsmith-18.0.0 lib/gemsmith/configuration/loader.rb
gemsmith-17.0.1 lib/gemsmith/configuration/loader.rb
gemsmith-17.0.0 lib/gemsmith/configuration/loader.rb
gemsmith-16.2.0 lib/gemsmith/configuration/loader.rb
gemsmith-16.1.0 lib/gemsmith/configuration/loader.rb
gemsmith-16.0.0 lib/gemsmith/configuration/loader.rb