Sha256: 150ef29b7cecd1bdf71cb36bcf5b961451c8091b58c995d85953c227bf2a00ce

Contents?: true

Size: 1.14 KB

Versions: 104

Compression:

Stored size: 1.14 KB

Contents

# Implements:
#
#   template - uses @definition to build a CloudFormation template section
#
class Jets::Stack
  class Parameter
    autoload :Dsl, "jets/stack/parameter/dsl"
    include Definition

    def template
      camelize(add_required(standarize(@definition)))
    end

    # Type is the only required property: https://amzn.to/2x8W5aD
    def standarize(definition)
      first, second, _ = 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, properties = first, second
        { logical_id => properties }
      elsif (definition.size == 2 && second.is_a?(String)) || # short form
            definition.size == 1
        logical_id = first
        properties = second.is_a?(String) ? { default: second } : {}
        { logical_id => properties }
      else # I dont know what form
        raise "Invalid form provided. definition #{definition.inspect}"
      end
    end

    def add_required(attributes)
      properties = attributes.values.first
      properties[:type] ||= 'String'
      attributes
    end
  end
end

Version data entries

104 entries across 104 versions & 2 rubygems

Version Path
jets-1.3.9 lib/jets/stack/parameter.rb
jets-1.3.8 lib/jets/stack/parameter.rb
jets-1.3.7 lib/jets/stack/parameter.rb
jets-1.3.6 lib/jets/stack/parameter.rb
jets-1.3.5 lib/jets/stack/parameter.rb
jets-1.3.4 lib/jets/stack/parameter.rb
jets-1.3.3 lib/jets/stack/parameter.rb
jets-1.3.2 lib/jets/stack/parameter.rb
jets-1.3.1 lib/jets/stack/parameter.rb
jets-1.3.0 lib/jets/stack/parameter.rb
jets-1.2.1 lib/jets/stack/parameter.rb
jets-1.2.0 lib/jets/stack/parameter.rb
jets-1.1.5 lib/jets/stack/parameter.rb
jets-1.1.4 lib/jets/stack/parameter.rb
jets-1.1.3 lib/jets/stack/parameter.rb
jets-1.1.2 lib/jets/stack/parameter.rb
jets-1.1.1 lib/jets/stack/parameter.rb
jets-1.1.0 lib/jets/stack/parameter.rb
jets-1.0.18 lib/jets/stack/parameter.rb
jets-1.0.17 lib/jets/stack/parameter.rb