Sha256: 07c6c3b53d090550e7536527bcd1e0cdcc8529f205c2d3ceebeb76e867f2071a

Contents?: true

Size: 1.18 KB

Versions: 6

Compression:

Stored size: 1.18 KB

Contents

# Implements:
#
#   template - uses @definition to build a CloudFormation template section
#
class Lono::Template::Dsl::Builder
  class Output < Base
    def template
      camelize(standarize(@definition))
    end

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
lono-5.2.2 lib/lono/template/dsl/builder/output.rb
lono-5.2.1 lib/lono/template/dsl/builder/output.rb
lono-5.2.0 lib/lono/template/dsl/builder/output.rb
lono-5.1.1 lib/lono/template/dsl/builder/output.rb
lono-5.1.0 lib/lono/template/dsl/builder/output.rb
lono-5.0.1 lib/lono/template/dsl/builder/output.rb