Sha256: 9e843ecd5ce2b5edb13ca3eb2ea2d9dab018cdebe374e0d0650ce5c04a0832d1

Contents?: true

Size: 1.41 KB

Versions: 4

Compression:

Stored size: 1.41 KB

Contents

class Jets::Cfn::Resource
  class Standardizer
    include Jets::Util::Camelize

    attr_reader :definition
    def initialize(*definition)
      @definition = definition.flatten
    end

    def template
      camelize(standarize(@definition))
    end

    def standarize(definition)
      definition = camelize(definition)
      first, second, third, _ = definition
      if definition.size == 1 && first.is_a?(Hash) # long form
        attrs = first.values.first
        attrs.delete(:Properties) if attrs[:Properties].blank?
        first # pass through
      elsif definition.size == 2 && second.is_a?(Hash) # medium form
        logical_id, attributes = first, second
        attributes.delete(:Properties) if attributes[:Properties].blank?
        {logical_id => attributes}
      elsif definition.size == 2 && second.is_a?(String) # short form
        logical_id, type = first, second
        {logical_id => {
          Type: type
        }}
      elsif definition.size == 3 && (second.is_a?(String) || second.is_a?(NilClass)) # short form
        logical_id, type, properties = first, second, third
        template = {logical_id => {
          Type: type
        }}
        attributes = template.values.first
        attributes[:Properties] = properties unless properties.empty?
        template
      else # Dont understand this form
        raise "Invalid form provided. definition #{definition.inspect}"
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
jets-6.0.5 lib/jets/cfn/resource/standardizer.rb
jets-6.0.4 lib/jets/cfn/resource/standardizer.rb
jets-6.0.3 lib/jets/cfn/resource/standardizer.rb
jets-6.0.2 lib/jets/cfn/resource/standardizer.rb