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_cli' => 'auto',
  'github_user' => ENV.fetch('USER'),
  'fallthru' => true,
  'pr_autofill' => true,
  'pr_autostack' => nil,
}.freeze

Class Method Summary collapse

Class Method Details

._find_ordered_filesObject



16
17
18
19
20
21
# File 'lib/sugarjar/config.rb', line 16

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

.configObject



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/sugarjar/config.rb', line 23

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(f)
    # an empty file is a `nil` which you can't merge
    c.merge!(YAML.safe_load_file(f)) if data
    SugarJar::Log.debug("Modified config: #{c}")
  end
  c
end