Class: SugarJar::Config
- Inherits:
-
Object
- Object
- SugarJar::Config
- 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.fetch('USER'), 'pr_autofill' => true, 'pr_autostack' => nil, 'color' => true, 'ignore_deprecated_options' => [], }.freeze
Class Method Summary collapse
Class Method Details
._find_ordered_files ⇒ Object
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 |
.config ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# 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) warn_on_deprecated_configs(data, 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 |
.warn_on_deprecated_configs(data, fname) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/sugarjar/config.rb', line 37 def self.warn_on_deprecated_configs(data, fname) = data['ignore_deprecated_options'] || [] %w{fallthru gh_cli}.each do |opt| next unless data.key?(opt) if .include?(opt) SugarJar::Log.debug( "Not warning about deprecated option '#{opt}' in #{fname} due to " + '"ignore_deprecated_options" in that file.', ) next end SugarJar::Log.warn( "Config file #{fname} contains deprecated option #{opt}. You can " + 'suppress this warning with ignore_deprecated_options.', ) end end |