Sha256: 9e866c6d3637c35bc3978a7cc2554d7e534f9d4515ab47cec73cc8adeac4cafd

Contents?: true

Size: 877 Bytes

Versions: 1046

Compression:

Stored size: 877 Bytes

Contents

require 'json'

module Aws
  module Resources
    class Source

      def initialize(definition, file = nil)
        @definition = definition
        @file = file
      end

      # @return [Hash]
      attr_reader :definition

      # @return [String, nil]
      attr_reader :file

      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

    end
  end
end

Version data entries

1,046 entries across 1,046 versions & 2 rubygems

Version Path
aws-sdk-resources-2.11.572 lib/aws-sdk-resources/source.rb
aws-sdk-resources-2.11.571 lib/aws-sdk-resources/source.rb
aws-sdk-resources-2.11.570 lib/aws-sdk-resources/source.rb
aws-sdk-resources-2.11.569 lib/aws-sdk-resources/source.rb
aws-sdk-resources-2.11.568 lib/aws-sdk-resources/source.rb
aws-sdk-resources-2.11.567 lib/aws-sdk-resources/source.rb
aws-sdk-resources-2.11.566 lib/aws-sdk-resources/source.rb
aws-sdk-resources-2.11.565 lib/aws-sdk-resources/source.rb
aws-sdk-resources-2.11.564 lib/aws-sdk-resources/source.rb
aws-sdk-resources-2.11.563 lib/aws-sdk-resources/source.rb
aws-sdk-resources-2.11.562 lib/aws-sdk-resources/source.rb
aws-sdk-resources-2.11.561 lib/aws-sdk-resources/source.rb
aws-sdk-resources-2.11.560 lib/aws-sdk-resources/source.rb
aws-sdk-resources-2.11.559 lib/aws-sdk-resources/source.rb
aws-sdk-resources-2.11.558 lib/aws-sdk-resources/source.rb
aws-sdk-resources-2.11.557 lib/aws-sdk-resources/source.rb
aws-sdk-resources-2.11.556 lib/aws-sdk-resources/source.rb
aws-sdk-resources-2.11.555 lib/aws-sdk-resources/source.rb
aws-sdk-resources-2.11.554 lib/aws-sdk-resources/source.rb
aws-sdk-resources-2.11.553 lib/aws-sdk-resources/source.rb