Sha256: a96a8c7b901e5a7f92a3d31e11d7e9647a15b4e8287c9225ddc9815a1382d2f8

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

Contents

require 'bora/stack'

class Bora
  class Template
    INHERITABLE_PROPERTIES = ["capabilities", "default_region"]

    def initialize(template_name, template_config, override_config = {})
      @template_name = template_name
      @template_config = template_config
      @stacks = {}
      template_config['stacks'].each do |stack_name, stack_config|
        stack_name = "#{template_name}-#{stack_name}"
        stack_config = resolve_stack_config(template_config, stack_config, override_config)
        @stacks[stack_name] = Stack.new(stack_name, template_config['template_file'], stack_config)
      end
    end

    def stack(name)
      @stacks[name]
    end

    def stacks
      @stacks.values
    end

    def rake_tasks
      @stacks.each { |_, s| s.rake_tasks }
    end


    private

    def resolve_stack_config(template_config, stack_config, override_config)
      inheritable_properties(template_config).merge(stack_config).merge(inheritable_properties(override_config))
    end

    def inheritable_properties(config)
      config.select { |k| INHERITABLE_PROPERTIES.include?(k) }
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bora-1.1.1 lib/bora/template.rb
bora-1.1.0 lib/bora/template.rb