Class: Yle::AWS::Role::Config

Inherits:
Struct
  • Object
show all
Defined in:
lib/yle/aws/role/config.rb

Overview

rubocop:disable Metrics/BlockLength

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#accountsObject

Returns the value of attribute accounts

Returns:

  • (Object)

    the current value of accounts



7
8
9
# File 'lib/yle/aws/role/config.rb', line 7

def accounts
  @accounts
end

#defaultsObject

Returns the value of attribute defaults

Returns:

  • (Object)

    the current value of defaults



7
8
9
# File 'lib/yle/aws/role/config.rb', line 7

def defaults
  @defaults
end

Class Method Details

.default_configObject



12
13
14
# File 'lib/yle/aws/role/config.rb', line 12

def self.default_config
  @default_config ||= Config.new({}, {})
end

.default_config=(config) ⇒ Object



16
17
18
# File 'lib/yle/aws/role/config.rb', line 16

def self.default_config=(config)
  @default_config = default_config.merge(config)
end

.default_pathObject



8
9
10
# File 'lib/yle/aws/role/config.rb', line 8

def self.default_path
  ENV.fetch('ASU_CONFIG') { File.join(Dir.home, '.aws', 'asu.yaml') }
end

.load(paths = nil) ⇒ Object



20
21
22
23
24
25
# File 'lib/yle/aws/role/config.rb', line 20

def self.load(paths = nil)
  paths = Array(paths).push(default_path)
  paths.inject(default_config) do |config, path|
    config.merge(load_yaml(path))
  end
end

.load_yaml(path) ⇒ Object



27
28
29
30
31
32
# File 'lib/yle/aws/role/config.rb', line 27

def self.load_yaml(path)
  (path && File.exist?(path) && YAML.load_file(path)) || {}
rescue StandardError
  STDERR.puts("WARN: Failed to load or parse configuration from '#{path}'")
  {}
end

Instance Method Details

#merge(config) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/yle/aws/role/config.rb', line 34

def merge(config)
  config ||= {}
  Config.new(
    accounts.merge(config['accounts'] || {}),
    defaults.merge(config['defaults'] || {})
  )
end