Class: StackMaster::Config

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

Constant Summary collapse

ConfigParseError =
Class.new(StandardError)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, base_dir) ⇒ Config

Returns a new instance of Config.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/stack_master/config.rb', line 39

def initialize(config, base_dir)
  @config = config
  @base_dir = base_dir
  @template_dir = config.fetch('template_dir', nil)
  @parameters_dir = config.fetch('parameters_dir', nil)
  @stack_defaults = config.fetch('stack_defaults', {})
  @region_aliases = Utils.underscore_keys_to_hyphen(config.fetch('region_aliases', {}))
  @region_to_aliases = @region_aliases.inject({}) do |hash, (key, value)|
    hash[value] ||= []
    hash[value] << key
    hash
  end
  @region_defaults = normalise_region_defaults(config.fetch('region_defaults', {}))
  @stacks = []
  load_template_compilers(config)
  load_config
end

Class Method Details

.load!(config_file = 'stack_master.yml') ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/stack_master/config.rb', line 8

def self.load!(config_file = 'stack_master.yml')
  resolved_config_file = search_up_and_chdir(config_file)
  config = YAML.load(File.read(resolved_config_file))
  base_dir = File.dirname(File.expand_path(resolved_config_file))
  new(config, base_dir)
rescue Psych::SyntaxError => error
  raise ConfigParseError, "Unable to parse #{resolved_config_file}: #{error}"
end

Instance Method Details

#filter(region = nil, stack_name = nil) ⇒ Object



57
58
59
60
61
62
# File 'lib/stack_master/config.rb', line 57

def filter(region = nil, stack_name = nil)
  @stacks.select do |s|
    (region.blank? || s.region == region || s.region == region.gsub('_', '-')) &&
      (stack_name.blank? || s.stack_name == stack_name || s.stack_name == stack_name.gsub('_', '-'))
  end
end

#find_stack(region, stack_name) ⇒ Object



64
65
66
# File 'lib/stack_master/config.rb', line 64

def find_stack(region, stack_name)
  filter(region, stack_name).first
end

#unalias_region(region) ⇒ Object



68
69
70
# File 'lib/stack_master/config.rb', line 68

def unalias_region(region)
  @region_aliases.fetch(region) { region }
end