Module: Pangea::Config

Defined in:
lib/pangea/config.rb

Constant Summary collapse

CONFIG_PATHS =

File paths in increasing order of priority.

[
  '/etc/pangea/config.yml',
  File.expand_path('~/.config/pangea/config.yml'),
  'pangea.yml'
].freeze

Class Method Summary collapse

Class Method Details

.configObject

Public: Returns a memoized configuration Hash. The configuration is lazily loaded and deep-merged so that:

  • Keys in pangea.yml override keys in ~/.config/pangea/config.yml

  • Keys in ~/.config/pangea/config.yml override keys in /etc/pangea/config.yml



11
12
13
# File 'lib/pangea/config.rb', line 11

def config
  @config ||= load_config
end

.load_configObject

Loads and deep-merges available YAML configuration files.



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

def load_config
  merged = {}
  CONFIG_PATHS.each do |file_path|
    if File.exist?(file_path)
      data = YAML.load_file(file_path)
      merged = Pangea::Utils.deep_merge(merged, data) if data.is_a?(Hash)
    end
  end
  merged
end