Sha256: cd14d1d57f1e2a928a99b370c255143b228d6decf5fafa1e77d413a1faa8cb8e

Contents?: true

Size: 1.48 KB

Versions: 8

Compression:

Stored size: 1.48 KB

Contents

require "yaml"
require "colorize"
require "bora/version"
require "bora/template"
require "bora/tasks"

class Bora
  DEFAULT_CONFIG_FILE = "bora.yml"
  INHERITABLE_PROPERTIES = ["default_region"]

  def initialize(config_file_or_hash: DEFAULT_CONFIG_FILE, override_config: {}, colorize: true)
    @templates = {}
    config = load_config(config_file_or_hash)
    String.disable_colorization = !colorize
    raise "No templates defined" if !config['templates']
    config['templates'].each do |template_name, template_config|
      resolved_config = resolve_template_config(config, template_config, override_config)
      @templates[template_name] = Template.new(template_name, resolved_config, override_config)
    end
  end

  def template(name)
    @templates[name]
  end

  def templates
    @templates.values
  end

  def stack(stack_name)
    t = @templates.find { |_, template| template.stack(stack_name) != nil }
    t ? t[1].stack(stack_name) : nil
  end

  def rake_tasks
    @templates.each { |_, t| t.rake_tasks }
  end


  protected

  def load_config(config)
    if config.class == String
      return YAML.load_file(config)
    elsif config.class == Hash
      return config
    end
  end


  private

  def resolve_template_config(bora_config, template_config, override_config)
    inheritable_properties(bora_config).merge(template_config).merge(inheritable_properties(override_config))
  end

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

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
bora-1.6.0 lib/bora.rb
bora-1.5.0 lib/bora.rb
bora-1.4.1 lib/bora.rb
bora-1.4.0 lib/bora.rb
bora-1.3.0 lib/bora.rb
bora-1.2.0 lib/bora.rb
bora-1.1.1 lib/bora.rb
bora-1.1.0 lib/bora.rb