Class: CfnFlow::StackParams

Inherits:
Hash
  • Object
show all
Defined in:
lib/cfn_flow/stack_params.rb

Overview

Extend hash with some special behavior to generate the style of hash aws-sdk expects

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.expanded(hash) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/cfn_flow/stack_params.rb', line 6

def self.expanded(hash)
  self[hash].
    with_symbolized_keys.
    with_expanded_parameters.
    with_expanded_tags.
    with_expanded_template_body
end

Instance Method Details

#add_tag(hash) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/cfn_flow/stack_params.rb', line 41

def add_tag(hash)
  new_tags = hash.map do |k,v|
    {key: k, value: v }
  end
  tags = (self[:tags] || []) + new_tags
  self.merge(tags: tags)
end

#with_expanded_parametersObject



21
22
23
24
25
26
27
28
29
# File 'lib/cfn_flow/stack_params.rb', line 21

def with_expanded_parameters
  return self unless self[:parameters].is_a? Hash

  expanded_params = self[:parameters].map do |key,value|
    { parameter_key: key, parameter_value: fetch_value(key, value) }
  end

  self.merge(parameters: expanded_params)
end

#with_expanded_tagsObject



31
32
33
34
35
36
37
38
39
# File 'lib/cfn_flow/stack_params.rb', line 31

def with_expanded_tags
  return self unless self[:tags].is_a? Hash

  tags = self[:tags].map do |key, value|
    {key: key, value: value}
  end

  self.merge(tags: tags)
end

#with_expanded_template_bodyObject



49
50
51
52
53
54
55
56
# File 'lib/cfn_flow/stack_params.rb', line 49

def with_expanded_template_body
  return self unless self[:template_body].is_a? String
  body = CfnFlow::Template.new(self[:template_body]).to_json
  self.merge(template_body: body)
rescue CfnFlow::Template::Error
  # Do nothing
  self
end

#with_symbolized_keysObject



14
15
16
17
18
19
# File 'lib/cfn_flow/stack_params.rb', line 14

def with_symbolized_keys
  self.inject(StackParams.new) do |accum, pair|
    key, value = pair
    accum.merge(key.to_sym => value)
  end
end