Class: Cloudshaper::StackModule
- Inherits:
-
Object
- Object
- Cloudshaper::StackModule
- Defined in:
- lib/cloudshaper/stack_module.rb
Overview
Stack Modules contain stack elements. A stack is made up of a root module, which may have submodules
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#secrets ⇒ Object
Returns the value of attribute secrets.
Class Method Summary collapse
Instance Method Summary collapse
- #build(**kwargs) ⇒ Object
- #clone ⇒ Object
- #each_variable(&b) ⇒ Object
- #generate ⇒ Object
- #get(variable) ⇒ Object
- #get_resource(type, id) ⇒ Object
- #id ⇒ Object
-
#initialize(name, &block) ⇒ StackModule
constructor
A new instance of StackModule.
Constructor Details
#initialize(name, &block) ⇒ StackModule
Returns a new instance of StackModule.
35 36 37 38 39 40 41 |
# File 'lib/cloudshaper/stack_module.rb', line 35 def initialize(name, &block) @name = name @stack_elements = { resource: {}, provider: {}, variable: {}, output: {}, module: {} } @secrets = {} @block = block variable(:cloudshaper_stack_id) { default '' } end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
33 34 35 |
# File 'lib/cloudshaper/stack_module.rb', line 33 def name @name end |
#secrets ⇒ Object
Returns the value of attribute secrets.
33 34 35 |
# File 'lib/cloudshaper/stack_module.rb', line 33 def secrets @secrets end |
Class Method Details
.define(name, &block) ⇒ Object
15 16 17 18 |
# File 'lib/cloudshaper/stack_module.rb', line 15 def define(name, &block) template = new(name, &block) StackModules.register(name, template) end |
.flatten_variable_arrays(variables) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/cloudshaper/stack_module.rb', line 20 def flatten_variable_arrays(variables) vars = variables.map do |k, v| if v.is_a?(Hash) && v.key?(:default) && v[:default].is_a?(Array) v[:default] = v[:default].join(',') elsif v.is_a?(Array) v = v.join(',') end [k, v] end Hash[vars] end |
Instance Method Details
#build(**kwargs) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/cloudshaper/stack_module.rb', line 48 def build(**kwargs) vars = Hash[kwargs.map { |k, v| [k, { default: v }] }] @stack_elements[:variable].merge!(vars) b = @block instance_eval(&b) end |
#clone ⇒ Object
43 44 45 46 |
# File 'lib/cloudshaper/stack_module.rb', line 43 def clone b = @block StackModule.new(@name, &b) end |
#each_variable(&b) ⇒ Object
67 68 69 |
# File 'lib/cloudshaper/stack_module.rb', line 67 def each_variable(&b) elements[:variable].each(&b) end |
#generate ⇒ Object
55 56 57 |
# File 'lib/cloudshaper/stack_module.rb', line 55 def generate JSON.pretty_generate(elements) end |
#get(variable) ⇒ Object
63 64 65 |
# File 'lib/cloudshaper/stack_module.rb', line 63 def get(variable) elements[:variable].fetch(variable)[:default] end |
#get_resource(type, id) ⇒ Object
71 72 73 |
# File 'lib/cloudshaper/stack_module.rb', line 71 def get_resource(type, id) @stack_elements[:resource].fetch(type).fetch(id) end |
#id ⇒ Object
59 60 61 |
# File 'lib/cloudshaper/stack_module.rb', line 59 def id get(:cloudshaper_stack_id) end |