class Runcom::Config

A developer friendly wrapper of XDG config.

Constants

DEFAULT_CONTEXT

Public Class Methods

new(path, defaults: {}) click to toggle source
# File lib/runcom/config.rb, line 16
def initialize path, defaults: {}, context: DEFAULT_CONTEXT
  @common = Paths::Common.new path, context: context
  @context = context
  @settings = defaults.deep_merge process_settings
  freeze
end

Public Instance Methods

==(other) click to toggle source

:reek: FeatureEnvy

# File lib/runcom/config.rb, line 28
def == other
  other.is_a?(Config) && hash == other.hash
end
Also aliased as: eql?
eql?(other)
Alias for: ==
hash(= [common.relative, to_h, self.class].hash) click to toggle source
# File lib/runcom/config.rb, line 34
    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 => error
      raise Errors::Syntax, error.message
    rescue StandardError
      context.defaults
      {}
    end

    def load_settings
      yaml = YAML.load_file common.current
      yaml.is_a?(Hash) ? yaml : {}
    end
  end
end
load_settings() click to toggle source
# File lib/runcom/config.rb, line 51
def load_settings
  yaml = YAML.load_file common.current
  yaml.is_a?(Hash) ? yaml : {}
end
merge(other) click to toggle source
# File lib/runcom/config.rb, line 23
def merge other
  self.class.new common.relative, defaults: settings.deep_merge(other.to_h), context: context
end
process_settings() click to toggle source
# File lib/runcom/config.rb, line 42
def process_settings
  load_settings
rescue Psych::SyntaxError => error
  raise Errors::Syntax, error.message
rescue StandardError
  context.defaults
  {}
end
to_h(= settings) click to toggle source
# File lib/runcom/config.rb, line 36
  def to_h = settings

  private

  attr_reader :common, :context, :settings

  def process_settings
    load_settings
  rescue Psych::SyntaxError => error
    raise Errors::Syntax, error.message
  rescue StandardError
    context.defaults
    {}
  end

  def load_settings
    yaml = YAML.load_file common.current
    yaml.is_a?(Hash) ? yaml : {}
  end
end