class Runcom::Configuration

Default gem configuration with support for custom settings.

Attributes

defaults[R]
path[R]
paths[R]
settings[R]

Public Class Methods

new(project_name:, file_name: "configuration.yml", defaults: {}) click to toggle source
# File lib/runcom/configuration.rb, line 14
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

Public Instance Methods

merge(custom_settings) click to toggle source
# File lib/runcom/configuration.rb, line 20
def merge custom_settings
  settings.deep_merge custom_settings
end
to_h() click to toggle source
# File lib/runcom/configuration.rb, line 24
def to_h
  settings
end

Private Instance Methods

load_path(project, file) click to toggle source
# File lib/runcom/configuration.rb, line 32
def load_path project, file
  paths = XDG::Configuration.computed_dirs.map { |root| Pathname "#{root}/#{project}/#{file}" }
  paths.find(&:exist?)
end
load_settings() click to toggle source
# File lib/runcom/configuration.rb, line 37
def load_settings
  yaml = YAML.load_file path
  yaml.is_a?(Hash) ? yaml : {}
end
process_settings() click to toggle source
# File lib/runcom/configuration.rb, line 42
def process_settings
  load_settings
rescue Psych::SyntaxError => error
  raise Errors::Syntax, error.message
rescue StandardError
  defaults
end