Class: Stacker::Stack::Template::JSONFormatter
- Inherits:
-
Object
- Object
- Stacker::Stack::Template::JSONFormatter
- Defined in:
- lib/stacker/stack/template.rb
Constant Summary collapse
- STR =
'\"[^\"]+\"'
Class Method Summary collapse
Class Method Details
.format(object) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/stacker/stack/template.rb', line 106 def self.format object formatted = JSON.pretty_generate object # put empty arrays on a single line formatted.gsub! /: \[\s*\]/m, ': []' # put { "Ref": ... } on a single line formatted.gsub! /\{\s+\"Ref\"\:\s+(?<ref>#{STR})\s+\}/m, '{ "Ref": \\k<ref> }' # put { "Fn::GetAtt": ... } on a single line formatted.gsub! /\{\s+\"Fn::GetAtt\"\: \[\s+(?<key>#{STR}),\s+(?<val>#{STR})\s+\]\s+\}/m, '{ "Fn::GetAtt": [ \\k<key>, \\k<val> ] }' formatted + "\n" end |