Class: Aws::Cfn::Dsl::Base
- Inherits:
-
Aws::Cfn::DeCompiler::Base
- Object
- Aws::Cfn::DeCompiler::Base
- Aws::Cfn::Dsl::Base
- Defined in:
- lib/aws/cfn/dsl/base.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize ⇒ Base
constructor
A new instance of Base.
- #pprint(val) ⇒ Object
- #simplify(val) ⇒ Object
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
9 10 11 |
# File 'lib/aws/cfn/dsl/base.rb', line 9 def initialize @output = [] end |
Instance Method Details
#pprint(val) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/aws/cfn/dsl/base.rb', line 55 def pprint(val) case detect_type(val) when :template pprint_cfn_template(val) when :parameter pprint_cfn_section 'parameter', 'TODO', val, 'Parameters' when :resource pprint_cfn_resource 'TODO', val when :parameters val.each { |k, v| pprint_cfn_section 'parameter', k, v, 'Parameters' } when :resources val.each { |k, v| pprint_cfn_resource k, v } else pprint_value(val, '') end end |
#simplify(val) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/aws/cfn/dsl/base.rb', line 13 def simplify(val) 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 # 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] # Aws::Cfn::DSL functions when k.match(%r'^Aws::Cfn::DSL') FnCall.new k, [v] else val end end elsif val.is_a?(Array) val.map { |v| simplify(v) } else val end end |