Class: Humidifier::Stack

Inherits:
Object
  • Object
show all
Defined in:
lib/humidifier/stack.rb

Overview

Represents a CFN stack

Constant Summary collapse

STATIC_RESOURCES =

Single settings on the stack

Utils.underscored(%w[AWSTemplateFormatVersion Description Metadata])
ENUMERABLE_RESOURCES =

Lists of objects linked to the stack

Utils.underscored(%w[Conditions Mappings Outputs Parameters Resources])

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Stack


14
15
16
17
18
19
20
21
# File 'lib/humidifier/stack.rb', line 14

def initialize(opts = {})
  self.name = opts[:name]
  self.id   = opts[:id]
  self.default_identifier = self.class.next_default_identifier

  ENUMERABLE_RESOURCES.values.each { |prop| send(:"#{prop}=", opts.fetch(prop, {})) }
  STATIC_RESOURCES.values.each { |prop| send(:"#{prop}=", opts[prop]) }
end

Class Method Details

.next_default_identifierObject

Increment the default identifier


56
57
58
59
60
# File 'lib/humidifier/stack.rb', line 56

def self.next_default_identifier
  @count ||= 0
  @count += 1
  "humidifier-stack-template-#{@count}"
end

Instance Method Details

#add(name, resource, attributes = {}) ⇒ Object

Add a resource to the stack and optionally set its attributes


24
25
26
27
28
# File 'lib/humidifier/stack.rb', line 24

def add(name, resource, attributes = {})
  resources[name] = resource
  resource.update_attributes(attributes) if attributes.any?
  resource
end

#identifierObject

The identifier used by the shim to find the stack in CFN, prefers id to name


31
32
33
# File 'lib/humidifier/stack.rb', line 31

def identifier
  id || name || default_identifier
end

#to_cf(serializer = :json) ⇒ Object

A string representation of the stack that's valid for CFN


36
37
38
39
40
41
42
43
# File 'lib/humidifier/stack.rb', line 36

def to_cf(serializer = :json)
  resources = static_resources.merge(enumerable_resources)

  case serializer
  when :json then JSON.pretty_generate(resources)
  when :yaml then YAML.dump(resources)
  end
end