Class: Lono::Template::Dsl::Builder::Resource
- Defined in:
- lib/lono/template/dsl/builder/resource.rb,
lib/lono/template/dsl/builder/resource/property_mover.rb
Defined Under Namespace
Classes: PropertyMover
Constant Summary
Constants included from Fn
Instance Method Summary collapse
-
#clean(resource) ⇒ Object
Remove properties with nil value automatically.
-
#standarize(definition) ⇒ Object
Type is the only required property: amzn.to/2x8W5aD.
- #template ⇒ Object
Methods inherited from Base
Methods included from Helpers::ParamHelper
#conditional_parameter, #normalize_conditional_parameter_options, #optional_ref, #parameter
Methods included from Helpers::CoreHelper
#content, #dimensions, #file_s3_key, #render_file, #render_path, #s3_bucket, #setting, #tag_list, #tags, #user_data
Methods included from Fn
define_methods, #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
#clean(resource) ⇒ Object
Remove properties with nil value automatically
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/lono/template/dsl/builder/resource.rb', line 45 def clean(resource) logical_id = resource.keys.first attributes = resource[logical_id] properties = attributes["Properties"] if properties properties.delete_if { |k,v| v.nil? } resource[logical_id]["Properties"] = properties end resource end |
#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 37 38 39 40 41 42 |
# 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].blank? attributes.delete("Properties") if attributes["Properties"].blank? { logical_id => attributes } elsif definition.size == 2 && second.is_a?(String) # short form with no properties 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 resource = { logical_id => { Type: type }} attributes = resource.values.first property_mover = PropertyMover.new(resource, logical_id, properties) property_mover.move! attributes["Properties"] = properties unless properties.empty? resource else # Dont understand this form raise "Invalid form provided. definition #{definition.inspect}" end end |
#template ⇒ Object
7 8 9 |
# File 'lib/lono/template/dsl/builder/resource.rb', line 7 def template camelize(clean(standarize(@definition))) end |