Class: Lono::Template::Strategy::Dsl::Builder::Section::Parameter
- Defined in:
- lib/lono/template/strategy/dsl/builder/section/parameter.rb
Constant Summary
Constants included from Fn
Instance Attribute Summary collapse
-
#conditional ⇒ Object
readonly
Returns the value of attribute conditional.
-
#group_label ⇒ Object
Returns the value of attribute group_label.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
Instance Method Summary collapse
- #add_required(attributes) ⇒ Object
- #name ⇒ Object
-
#standarize(definition) ⇒ Object
Type is the only required property: amzn.to/2x8W5aD.
- #template ⇒ Object
- #track_conditional(attributes) ⇒ Object
- #track_label(attributes) ⇒ Object
- #valid_value?(o) ⇒ Boolean
Methods inherited from Base
Methods included from Lono::Template::Strategy::Dsl::Builder::Stringify
Methods included from Common::Helpers
#extract_scripts, #scripts_name, #scripts_s3_path, #setting
Methods included from Fn
#conditional_ref, define_methods, #fn, #fn_id, #get_att, #get_azs, included, #join, #ref, #sub
Constructor Details
This class inherits a constructor from Lono::Template::Strategy::Dsl::Builder::Section::Base
Instance Attribute Details
#conditional ⇒ Object (readonly)
Returns the value of attribute conditional.
8 9 10 |
# File 'lib/lono/template/strategy/dsl/builder/section/parameter.rb', line 8 def conditional @conditional end |
#group_label ⇒ Object
Returns the value of attribute group_label.
7 8 9 |
# File 'lib/lono/template/strategy/dsl/builder/section/parameter.rb', line 7 def group_label @group_label end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
8 9 10 |
# File 'lib/lono/template/strategy/dsl/builder/section/parameter.rb', line 8 def label @label end |
Instance Method Details
#add_required(attributes) ⇒ Object
36 37 38 39 40 |
# File 'lib/lono/template/strategy/dsl/builder/section/parameter.rb', line 36 def add_required(attributes) properties = attributes.values.first properties["Type"] ||= 'String' attributes end |
#name ⇒ Object
65 66 67 |
# File 'lib/lono/template/strategy/dsl/builder/section/parameter.rb', line 65 def name template.keys.first # logical_id or name end |
#standarize(definition) ⇒ Object
Type is the only required property: amzn.to/2x8W5aD
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/lono/template/strategy/dsl/builder/section/parameter.rb', line 15 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 - 1 logical_id, properties = first, second { logical_id => properties } elsif definition.size == 3 && !second.is_a?(Hash) && third.is_a?(Hash) # medium form variant - 2 third[:Default] = second # probably a String, Integer, or Float logical_id, properties = first, third { logical_id => properties } elsif (definition.size == 2 && valid_value?(second)) || # short form definition.size == 1 logical_id = first properties = valid_value?(second) ? { Default: second } : {} { logical_id => properties } else # I dont know what form raise "Invalid form provided. definition #{definition.inspect}" end end |
#template ⇒ Object
10 11 12 |
# File 'lib/lono/template/strategy/dsl/builder/section/parameter.rb', line 10 def template camelize(add_required(track_label(track_conditional(standarize(@definition))))) end |
#track_conditional(attributes) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/lono/template/strategy/dsl/builder/section/parameter.rb', line 46 def track_conditional(attributes) properties = attributes.values.first @conditional ||= properties[:Conditional] # flag for later properties.delete(:Conditional) # remove property, it's not a real property, used to flag conditional parameters # Ensure default if @conditional defaults = { Default: "" } properties.reverse_merge!(defaults) end attributes end |
#track_label(attributes) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/lono/template/strategy/dsl/builder/section/parameter.rb', line 58 def track_label(attributes) properties = attributes.values.first @label ||= properties[:Label] # flag for later properties.delete(:Label) # remove property, it's not a real property, used to build metadata interface attributes end |
#valid_value?(o) ⇒ Boolean
42 43 44 |
# File 'lib/lono/template/strategy/dsl/builder/section/parameter.rb', line 42 def valid_value?(o) o.is_a?(Float) || o.is_a?(Integer) || o.is_a?(String) || o.is_a?(TrueClass) || o.is_a?(FalseClass) end |