Class: TFDSL::Stack
- Inherits:
-
Object
- Object
- TFDSL::Stack
- 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
-
#initialize(&block) ⇒ Stack
constructor
A new instance of Stack.
- #to_json ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(&block) ⇒ Stack
Returns a new instance of Stack.
6 7 8 9 |
# File 'lib/tfdsl/stack.rb', line 6 def initialize(&block) @objects = [] instance_eval(&block) if block_given? end |
Instance Method Details
#to_json ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/tfdsl/stack.rb', line 26 def to_json stack = {} @objects.each do |obj| key = KindTranslator.kind obj.class stack[key] = {} if stack[key].nil? stack[key] = stack[key].deep_merge obj.to_json_repr end JSON.pretty_generate(stack) end |
#to_s ⇒ Object
22 23 24 |
# File 'lib/tfdsl/stack.rb', line 22 def to_s @objects.each_with_object('') { |o, str| str << o } end |