Class: StackMaster::Config
- Inherits:
-
Object
- Object
- StackMaster::Config
- Defined in:
- lib/stack_master/config.rb
Constant Summary collapse
- ConfigParseError =
Class.new(StandardError)
Class Method Summary collapse
Instance Method Summary collapse
- #filter(region = nil, stack_name = nil) ⇒ Object
- #find_stack(region, stack_name) ⇒ Object
-
#initialize(config, base_dir) ⇒ Config
constructor
A new instance of Config.
- #unalias_region(region) ⇒ Object
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 56 57 |
# 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 = [] raise ConfigParseError.new("Stack defaults can't be undefined") if @stack_defaults.nil? 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.(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
59 60 61 62 63 64 |
# File 'lib/stack_master/config.rb', line 59 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
66 67 68 |
# File 'lib/stack_master/config.rb', line 66 def find_stack(region, stack_name) filter(region, stack_name).first end |
#unalias_region(region) ⇒ Object
70 71 72 |
# File 'lib/stack_master/config.rb', line 70 def unalias_region(region) @region_aliases.fetch(region) { region } end |