Sha256: 82387093b8b301191714c51f2c35fb83dac3c5bb2de391e17c67d739c163534f

Contents?: true

Size: 1.74 KB

Versions: 14

Compression:

Stored size: 1.74 KB

Contents

module Aws
  module Cfn
    module Dsl
      module Simplify

        def simplify(val,start=false)
          logStep "Simplify a block ..." if start
          if val.is_a?(Hash)
            val = Hash[val.map { |k,v| [k, simplify(v)] }]
            if val.length != 1
              val
            else
              k, v = val.entries[0]
              case @config[:functions]
                when @on_yes_regex then
                  case
                    # CloudFormation functions
                    when k == 'Fn::Base64'
                      FnCall.new 'base64', [v], true
                    when k == 'Fn::FindInMap'
                      FnCall.new 'find_in_map', v
                    when k == 'Fn::GetAtt'
                      FnCall.new 'get_att', v
                    when k == 'Fn::GetAZs'
                      FnCall.new 'get_azs', v != '' ? [v] : []
                    when k == 'Fn::Join'
                      FnCall.new 'join', [v[0]] + v[1], true
                    when k == 'Fn::Select'
                      FnCall.new 'select', v
                    when k == 'Ref' && v == 'AWS::Region'
                      FnCall.new 'aws_region', []
                    when k == 'Ref' && v == 'AWS::StackName'
                      FnCall.new 'aws_stack_name', []
                    # CloudFormation internal references
                    when k == 'Ref'
                      FnCall.new 'ref', [v]
                    else
                      val
                  end
                else
                  val
              end
            end
          elsif val.is_a?(Array)
            val.map { |v| simplify(v) }
          else
            val
          end
        end


        def self.included(includer)

        end

      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
aws-cfn-dsl-0.9.7 lib/aws/cfn/dsl/mixins/simplify.rb
aws-cfn-dsl-0.9.6 lib/aws/cfn/dsl/mixins/simplify.rb
aws-cfn-dsl-0.9.5 lib/aws/cfn/dsl/mixins/simplify.rb
aws-cfn-dsl-0.9.4 lib/aws/cfn/dsl/mixins/simplify.rb
aws-cfn-dsl-0.9.3 lib/aws/cfn/dsl/mixins/simplify.rb
aws-cfn-dsl-0.9.2 lib/aws/cfn/dsl/mixins/simplify.rb
aws-cfn-dsl-0.9.1 lib/aws/cfn/dsl/mixins/simplify.rb
aws-cfn-dsl-0.8.5 lib/aws/cfn/dsl/mixins/simplify.rb
aws-cfn-dsl-0.8.4 lib/aws/cfn/dsl/mixins/simplify.rb
aws-cfn-dsl-0.8.3 lib/aws/cfn/dsl/mixins/simplify.rb
aws-cfn-dsl-0.8.2 lib/aws/cfn/dsl/mixins/simplify.rb
aws-cfn-dsl-0.8.1 lib/aws/cfn/dsl/mixins/simplify.rb
aws-cfn-dsl-0.8.0 lib/aws/cfn/dsl/mixins/simplify.rb
aws-cfn-dsl-0.7.0 lib/aws/cfn/dsl/mixins/simplify.rb