Sha256: a0135ea7ad4d4ebb66ad95748a6eef88e9a16fefeaf06864f6627fdc56900418
Contents?: true
Size: 1.21 KB
Versions: 4
Compression:
Stored size: 1.21 KB
Contents
# frozen_string_literal: true require "refinements/hashes" require "yaml" module Runcom # A developer friendly wrapper of XDG config. class Config extend Forwardable using Refinements::Hashes DEFAULT_CONTEXT = Context.new xdg: XDG::Config delegate %i[relative namespace file_name current all inspect] => :common def initialize path, defaults: {}, context: DEFAULT_CONTEXT @common = Paths::Common.new path, context: @context = context @settings = defaults.deep_merge process_settings freeze end def merge other self.class.new common.relative, defaults: settings.deep_merge(other.to_h), context: end # :reek:FeatureEnvy def ==(other) = other.is_a?(Config) && (hash == other.hash) alias eql? == def hash = [common.relative, to_h, self.class].hash def to_h = settings private attr_reader :common, :context, :settings def process_settings load_settings rescue Psych::SyntaxError raise Error, "Invalid configuration: #{common.current}." rescue StandardError context.defaults {} end def load_settings yaml = YAML.load_file common.current yaml.is_a?(Hash) ? yaml : {} end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
runcom-9.0.3 | lib/runcom/config.rb |
runcom-9.0.2 | lib/runcom/config.rb |
runcom-9.0.1 | lib/runcom/config.rb |
runcom-9.0.0 | lib/runcom/config.rb |