Class: Aws::Resources::Source
- Inherits:
-
Object
- Object
- Aws::Resources::Source
- Defined in:
- lib/aws-sdk-resources/source.rb
Instance Attribute Summary collapse
- #definition ⇒ Hash readonly
- #file ⇒ String? readonly
Instance Method Summary collapse
- #format ⇒ Object
-
#initialize(definition, file = nil) ⇒ Source
constructor
A new instance of Source.
Constructor Details
#initialize(definition, file = nil) ⇒ Source
Returns a new instance of Source.
7 8 9 10 |
# File 'lib/aws-sdk-resources/source.rb', line 7 def initialize(definition, file = nil) @definition = definition @file = file end |
Instance Attribute Details
#definition ⇒ Hash (readonly)
13 14 15 |
# File 'lib/aws-sdk-resources/source.rb', line 13 def definition @definition end |
#file ⇒ String? (readonly)
16 17 18 |
# File 'lib/aws-sdk-resources/source.rb', line 16 def file @file end |
Instance Method Details
#format ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# 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 |