Class: TFDSL::Stack

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

Overview

This class is the representation of a terraform stack, or in another words is a collection of terraform configuration blocks

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Stack

Returns a new instance of Stack.



5
6
7
8
# File 'lib/tfdsl/stack.rb', line 5

def initialize(&block)
  @objects = []
  instance_eval(&block) if block_given?
end

Instance Method Details

#to_jsonObject



25
26
27
28
29
30
31
32
33
# File 'lib/tfdsl/stack.rb', line 25

def to_json
  stack = {}
  @objects.each do |obj|
    key = KindTranslator.kind obj.class
    stack[key] = {} if stack[key].nil?
    stack[key] = stack[key].merge obj.to_json_repr
  end
  stack.to_json
end

#to_sObject



21
22
23
# File 'lib/tfdsl/stack.rb', line 21

def to_s
  @objects.each_with_object('') { |o, str| str << o }
end