Class: SugarJar::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/sugarjar/config.rb

Overview

This parses SugarJar configs (not to be confused with repoconfigs). This is stuff like log level, github-user, etc.

Constant Summary collapse

DEFAULTS =
{
  'github_user' => ENV['USER'],
  'fallthru' => true,
}.freeze

Class Method Summary collapse

Class Method Details

._find_ordered_filesObject



13
14
15
16
17
18
# File 'lib/sugarjar/config.rb', line 13

def self._find_ordered_files
  [
    '/etc/sugarjar/config.yaml',
    "#{ENV['HOME']}/.config/sugarjar/config.yaml",
  ].select { |f| File.exist?(f) }
end

.configObject



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/sugarjar/config.rb', line 20

def self.config
  SugarJar::Log.debug("Defaults: #{DEFAULTS}")
  c = DEFAULTS.dup
  _find_ordered_files.each do |f|
    SugarJar::Log.debug("Loading config #{f}")
    data = YAML.safe_load(File.read(f))
    # an empty file is a `nil` which you can't merge
    c.merge!(YAML.safe_load(File.read(f))) if data
    SugarJar::Log.debug("Modified config: #{c}")
  end
  c
end