Class: StackMaster::Config

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, base_dir) ⇒ Config

Returns a new instance of Config.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/stack_master/config.rb', line 18

def initialize(config, base_dir)
  @config = config
  @base_dir = base_dir
  @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_config
end

Instance Attribute Details

#base_dirObject

Returns the value of attribute base_dir.



12
13
14
# File 'lib/stack_master/config.rb', line 12

def base_dir
  @base_dir
end

#region_aliasesObject

Returns the value of attribute region_aliases.



12
13
14
# File 'lib/stack_master/config.rb', line 12

def region_aliases
  @region_aliases
end

#region_defaultsObject

Returns the value of attribute region_defaults.



12
13
14
# File 'lib/stack_master/config.rb', line 12

def region_defaults
  @region_defaults
end

#stack_defaultsObject

Returns the value of attribute stack_defaults.



12
13
14
# File 'lib/stack_master/config.rb', line 12

def stack_defaults
  @stack_defaults
end

#stacksObject

Returns the value of attribute stacks.



12
13
14
# File 'lib/stack_master/config.rb', line 12

def stacks
  @stacks
end

Class Method Details

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



6
7
8
9
10
# File 'lib/stack_master/config.rb', line 6

def self.load!(config_file = 'stack_master.yml')
  config = YAML.load(File.read(config_file))
  base_dir = File.dirname(File.expand_path(config_file))
  new(config, base_dir)
end

Instance Method Details

#find_stack(region, stack_name) ⇒ Object



33
34
35
36
37
38
# File 'lib/stack_master/config.rb', line 33

def find_stack(region, stack_name)
  @stacks.find do |s|
    (s.region == region || s.region == region.gsub('_', '-')) &&
      (s.stack_name == stack_name || s.stack_name == stack_name.gsub('_', '-'))
  end
end

#unalias_region(region) ⇒ Object



40
41
42
# File 'lib/stack_master/config.rb', line 40

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