Sha256: b09fb94563cc21d03ecf4be707fddcefb9f952aa227d06ae39b930d7dc5e0736
Contents?: true
Size: 1.24 KB
Versions: 3
Compression:
Stored size: 1.24 KB
Contents
# frozen_string_literal: true require "pathname" require "refinements/hashes" require "refinements/structs" require "runcom" require "yaml" module Rubysmith module Configuration # Represents the fully assembled Command Line Interface (CLI) configuration. class Loader using Refinements::Hashes using Refinements::Structs DEFAULTS = YAML.load_file(Pathname(__dir__).join("defaults.yml")).freeze CLIENT = Runcom::Config.new "#{Identity::NAME}/configuration.yml", defaults: DEFAULTS ENHANCERS = [ Enhancers::CurrentTime.new, Enhancers::GitEmail.new, Enhancers::GitHubUser.new, Enhancers::GitUser.new ].freeze def self.call(...) = new(...).call def self.with_defaults = new(client: DEFAULTS, enhancers: []) def initialize content: 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
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
rubysmith-1.1.1 | lib/rubysmith/configuration/loader.rb |
rubysmith-1.1.0 | lib/rubysmith/configuration/loader.rb |
rubysmith-1.0.0 | lib/rubysmith/configuration/loader.rb |