Class: StackMaster::Config
- Inherits:
-
Object
- Object
- StackMaster::Config
- Defined in:
- lib/stack_master/config.rb
Constant Summary collapse
- ConfigParseError =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#base_dir ⇒ Object
Returns the value of attribute base_dir.
-
#parameters_dir ⇒ Object
Returns the value of attribute parameters_dir.
-
#region_aliases ⇒ Object
Returns the value of attribute region_aliases.
-
#region_defaults ⇒ Object
Returns the value of attribute region_defaults.
-
#stack_defaults ⇒ Object
Returns the value of attribute stack_defaults.
-
#stacks ⇒ Object
Returns the value of attribute stacks.
-
#template_compilers ⇒ Object
Returns the value of attribute template_compilers.
-
#template_dir ⇒ Object
Returns the value of attribute template_dir.
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.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/stack_master/config.rb', line 41 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 |
Instance Attribute Details
#base_dir ⇒ Object
Returns the value of attribute base_dir.
17 18 19 |
# File 'lib/stack_master/config.rb', line 17 def base_dir @base_dir end |
#parameters_dir ⇒ Object
Returns the value of attribute parameters_dir.
17 18 19 |
# File 'lib/stack_master/config.rb', line 17 def parameters_dir @parameters_dir end |
#region_aliases ⇒ Object
Returns the value of attribute region_aliases.
17 18 19 |
# File 'lib/stack_master/config.rb', line 17 def region_aliases @region_aliases end |
#region_defaults ⇒ Object
Returns the value of attribute region_defaults.
17 18 19 |
# File 'lib/stack_master/config.rb', line 17 def region_defaults @region_defaults end |
#stack_defaults ⇒ Object
Returns the value of attribute stack_defaults.
17 18 19 |
# File 'lib/stack_master/config.rb', line 17 def stack_defaults @stack_defaults end |
#stacks ⇒ Object
Returns the value of attribute stacks.
17 18 19 |
# File 'lib/stack_master/config.rb', line 17 def stacks @stacks end |
#template_compilers ⇒ Object
Returns the value of attribute template_compilers.
17 18 19 |
# File 'lib/stack_master/config.rb', line 17 def template_compilers @template_compilers end |
#template_dir ⇒ Object
Returns the value of attribute template_dir.
17 18 19 |
# File 'lib/stack_master/config.rb', line 17 def template_dir @template_dir 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 |
.search_up_and_chdir(config_file) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/stack_master/config.rb', line 28 def self.search_up_and_chdir(config_file) return config_file unless File.dirname(config_file) == "." dir = Dir.pwd parent_dir = File.("..", Dir.pwd) while parent_dir != dir && !File.exist?(File.join(dir, config_file)) dir = parent_dir parent_dir = File.("..", dir) end File.join(dir, config_file) end |
Instance Method Details
#filter(region = nil, stack_name = nil) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/stack_master/config.rb', line 62 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
69 70 71 |
# File 'lib/stack_master/config.rb', line 69 def find_stack(region, stack_name) filter(region, stack_name).first end |
#unalias_region(region) ⇒ Object
73 74 75 |
# File 'lib/stack_master/config.rb', line 73 def unalias_region(region) @region_aliases.fetch(region) { region } end |