Class: TFDSL::Formatter
- Inherits:
-
Object
- Object
- TFDSL::Formatter
- 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
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/tfdsl/formatter.rb', line 18 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 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/tfdsl/formatter.rb', line 4 def kind(cls) kinds = { Provider => 'provider', TFModule => 'module', Locals => 'locals', Resource => 'resource', Variable => 'variable', DataSource => 'data', Output => 'output', Terraform => 'terraform' } kinds[cls] end |