class Aws::Resources::Source

Attributes

definition[R]

@return [Hash]

file[R]

@return [String, nil]

Public Class Methods

new(definition, file = nil) click to toggle source
# File lib/aws-sdk-resources/source.rb, line 7
def initialize(definition, file = nil)
  @definition = definition
  @file = file
end

Public Instance Methods

format() click to toggle source
# File lib/aws-sdk-resources/source.rb, line 18
def format
  json = JSON.pretty_generate(definition, indent: '  ', space: '')
  stack = [[]]
  json.lines.each do |line|
    if line.match(/({|\[)$/)
      stack.push([])
    end
    stack.last.push(line)
    if line.match(/(}|\]),?$/)
      frame = stack.pop
      if frame.size == 3 && !frame[1].match(/[{}]/)
        frame = [frame[0].rstrip, '', frame[1].strip, '', frame[2].lstrip]
      end
      stack.last.push(frame.join)
    end
  end
  stack.last.join
end