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])
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
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.
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/humidifier/stack.rb', line 15 def initialize(opts = {}) @name = opts[:name] @id = opts[:id] @default_identifier = self.class.next_default_identifier ENUMERABLE_RESOURCES.each_value do |property| instance_variable_set(:"@#{property}", opts.fetch(property, {})) end STATIC_RESOURCES.each_value do |property| instance_variable_set(:"@#{property}", opts[property]) end end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
12 13 14 |
# File 'lib/humidifier/stack.rb', line 12 def id @id end |
Class Method Details
.next_default_identifier ⇒ Object
Increment the default identifier
66 67 68 69 70 |
# File 'lib/humidifier/stack.rb', line 66 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
30 31 32 33 34 |
# File 'lib/humidifier/stack.rb', line 30 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
38 39 40 |
# File 'lib/humidifier/stack.rb', line 38 def identifier id || name || default_identifier end |
#to_cf(serializer = :json) ⇒ Object
A string representation of the stack that’s valid for CFN
43 44 45 46 47 48 49 50 |
# File 'lib/humidifier/stack.rb', line 43 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 |