Sha256: eb14a004b49af2e3789d405954eb11f0080c2095415abe406a2f420dfa54c024
Contents?: true
Size: 1.06 KB
Versions: 1
Compression:
Stored size: 1.06 KB
Contents
# frozen_string_literal: true require "pathname" require "yaml" require "refinements/hashes" module Runcom # Default gem configuration with support for custom settings. class Configuration using Refinements::Hashes attr_reader :path def initialize project_name:, file_name: "configuration.yml", defaults: {} @path = load_path project_name, file_name @defaults = defaults @settings = defaults.deep_merge process_settings end def merge custom_settings settings.deep_merge custom_settings end def to_h settings end private attr_reader :paths, :defaults, :settings def load_path project, file paths = XDG::Configuration.computed_dirs.map { |root| Pathname "#{root}/#{project}/#{file}" } paths.find(&:exist?) end def load_settings yaml = YAML.load_file path yaml.is_a?(Hash) ? yaml : {} end def process_settings load_settings rescue Psych::SyntaxError => error raise Errors::Syntax, error.message rescue defaults end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
runcom-1.3.0 | lib/runcom/configuration.rb |