Class: TFDSL::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/tfdsl/formatter.rb

Overview

Class responsible for formatting the string representation of terraform blocks

Instance Method Summary collapse

Instance Method Details

#format(tf_block) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/tfdsl/formatter.rb', line 8

def format(tf_block)
  @depth ||= 0
  str = []

  if @depth.zero?
    str << first_line(tf_block)
    close = true
  end

  str << local_vars(tf_block) unless local_vars(tf_block).empty?

  str << child_blocks(tf_block) unless tf_block.__blocks__.empty?
  str[1..-1] = str[1..-1].map { |line| line.gsub(/^/, ' ' * 4) } unless str[1..-1].nil?
  str << "}\n\n" if close
  str.join("\n")
end

#kind(cls) ⇒ Object



4
5
6
# File 'lib/tfdsl/formatter.rb', line 4

def kind(cls)
  KindTranslator.kind cls
end