Class: Jets::Cfn::Resource::Standardizer

Inherits:
Object
  • Object
show all
Includes:
Util::Camelize
Defined in:
lib/jets/cfn/resource/standardizer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util::Camelize

#camelize

Constructor Details

#initialize(*definition) ⇒ Standardizer

Returns a new instance of Standardizer.



6
7
8
# File 'lib/jets/cfn/resource/standardizer.rb', line 6

def initialize(*definition)
  @definition = definition.flatten
end

Instance Attribute Details

#definitionObject (readonly)

Returns the value of attribute definition.



5
6
7
# File 'lib/jets/cfn/resource/standardizer.rb', line 5

def definition
  @definition
end

Instance Method Details

#standarize(definition) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/jets/cfn/resource/standardizer.rb', line 14

def standarize(definition)
  definition = camelize(definition)
  first, second, third, _ = definition
  if definition.size == 1 && first.is_a?(Hash) # long form
    first # pass through
  elsif definition.size == 2 && second.is_a?(Hash) # medium form
    logical_id, attributes = first, second
    attributes.delete(:Properties) if attributes[:Properties].nil? || attributes[:Properties].empty?
    { logical_id => attributes }
  elsif definition.size == 2 && second.is_a?(String) # short form
    logical_id, type = first, second
    { logical_id => {
        Type: type
    }}
  elsif definition.size == 3 && (second.is_a?(String) || second.is_a?(NilClass))# short form
    logical_id, type, properties = first, second, third
    template = { logical_id => {
                   Type: type
                }}
    attributes = template.values.first
    attributes[:Properties] = properties unless properties.empty?
    template
  else # Dont understand this form
    raise "Invalid form provided. definition #{definition.inspect}"
  end
end

#templateObject



10
11
12
# File 'lib/jets/cfn/resource/standardizer.rb', line 10

def template
  camelize(standarize(@definition))
end