Sha256: 86ca9a7554effe435da9684022f7bee9136a568ef5f7de0c0227cea8b3d1d9b6

Contents?: true

Size: 1.22 KB

Versions: 14

Compression:

Stored size: 1.22 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) || 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) || second.nil?) # 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

14 entries across 14 versions & 1 rubygems

Version Path
lono-6.1.11 lib/lono/template/dsl/builder/output.rb
lono-6.1.10 lib/lono/template/dsl/builder/output.rb
lono-6.1.9 lib/lono/template/dsl/builder/output.rb
lono-6.1.8 lib/lono/template/dsl/builder/output.rb
lono-6.1.7 lib/lono/template/dsl/builder/output.rb
lono-6.1.6 lib/lono/template/dsl/builder/output.rb
lono-6.1.5 lib/lono/template/dsl/builder/output.rb
lono-6.1.4 lib/lono/template/dsl/builder/output.rb
lono-6.1.3 lib/lono/template/dsl/builder/output.rb
lono-6.1.2 lib/lono/template/dsl/builder/output.rb
lono-6.1.1 lib/lono/template/dsl/builder/output.rb
lono-6.1.0 lib/lono/template/dsl/builder/output.rb
lono-6.0.1 lib/lono/template/dsl/builder/output.rb
lono-6.0.0 lib/lono/template/dsl/builder/output.rb