Sha256: 1403aa44d9af3200b935a9c190826ec969b5a76a0161d2d960df00f6c915b502

Contents?: true

Size: 1.1 KB

Versions: 113

Compression:

Stored size: 1.1 KB

Contents

# Implements:
#
#   template - uses @definition to build a CloudFormation template section
#
class Jets::Stack
  class Parameter
    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

113 entries across 113 versions & 3 rubygems

Version Path
jets-2.1.1 lib/jets/stack/parameter.rb
jets-2.1.0 lib/jets/stack/parameter.rb
jets-2.0.6 lib/jets/stack/parameter.rb
jets-2.0.5 lib/jets/stack/parameter.rb
jets-2.0.4 lib/jets/stack/parameter.rb
jets-2.0.3 lib/jets/stack/parameter.rb
jets-2.0.1 lib/jets/stack/parameter.rb
jets-2.0.0 lib/jets/stack/parameter.rb
jets-1.9.32 lib/jets/stack/parameter.rb
jets-1.9.31 lib/jets/stack/parameter.rb
jets-1.9.30 lib/jets/stack/parameter.rb
jets-1.9.29 lib/jets/stack/parameter.rb
jets-1.9.28 lib/jets/stack/parameter.rb
jets-1.9.27 lib/jets/stack/parameter.rb
jets-1.9.26 lib/jets/stack/parameter.rb
jets-1.9.25 lib/jets/stack/parameter.rb
jets-1.9.24 lib/jets/stack/parameter.rb
jets-1.9.23 lib/jets/stack/parameter.rb
jets-1.9.22 lib/jets/stack/parameter.rb
jets-1.9.21 lib/jets/stack/parameter.rb