Class: Lono::Template::Dsl::Builder::Resource

Inherits:
Base
  • Object
show all
Defined in:
lib/lono/template/dsl/builder/resource.rb

Constant Summary

Constants included from Fn

Fn::FUNCTIONS

Instance Method Summary collapse

Methods inherited from Base

#camelize, #initialize

Methods included from Helper

#current_region, #extract_scripts, #indent, #partial, #partial_exist?, #scripts_name, #scripts_s3_path, #template_params, #template_s3_path, #user_data

Methods included from Fn

#fn, #fn_id, #get_att, #get_azs, included, #join, #ref, #sub

Constructor Details

This class inherits a constructor from Lono::Template::Dsl::Builder::Base

Instance Method Details

#standarize(definition) ⇒ Object

Type is the only required property: amzn.to/2x8W5aD



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/lono/template/dsl/builder/resource.rb', line 12

def standarize(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



7
8
9
# File 'lib/lono/template/dsl/builder/resource.rb', line 7

def template
  camelize(standarize(@definition))
end