Class: Humidifier::Stack
- Inherits:
-
Object
- Object
- Humidifier::Stack
- 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
-
.next_default_identifier ⇒ Object
Increment the default identifier.
Instance Method Summary collapse
-
#add(name, resource, attributes = {}) ⇒ Object
Add a resource to the stack and optionally set its attributes.
-
#identifier ⇒ Object
The identifier used by the shim to find the stack in CFN, prefers id to name.
-
#initialize(opts = {}) ⇒ Stack
constructor
A new instance of Stack.
-
#to_cf(serializer = :json) ⇒ Object
A string representation of the stack that’s valid for CFN.
Constructor Details
#initialize(opts = {}) ⇒ Stack
Returns a new instance of Stack.
12 13 14 15 16 17 18 19 |
# File 'lib/humidifier/stack.rb', line 12 def initialize(opts = {}) self.name = opts[:name] self.id = opts[:id] self.default_identifier = self.class.next_default_identifier ENUMERABLE_RESOURCES.each_value { |prop| send(:"#{prop}=", opts.fetch(prop, {})) } STATIC_RESOURCES.each_value { |prop| send(:"#{prop}=", opts[prop]) } end |
Class Method Details
.next_default_identifier ⇒ Object
Increment the default identifier
54 55 56 57 58 |
# File 'lib/humidifier/stack.rb', line 54 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
22 23 24 25 26 |
# File 'lib/humidifier/stack.rb', line 22 def add(name, resource, attributes = {}) resources[name] = resource resource.update_attributes(attributes) if attributes.any? resource end |
#identifier ⇒ Object
The identifier used by the shim to find the stack in CFN, prefers id to name
29 30 31 |
# File 'lib/humidifier/stack.rb', line 29 def identifier id || name || default_identifier end |
#to_cf(serializer = :json) ⇒ Object
A string representation of the stack that’s valid for CFN
34 35 36 37 38 39 40 41 |
# File 'lib/humidifier/stack.rb', line 34 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 |