Class: Kozo::Operations::Destroy

Inherits:
Kozo::Operation show all
Defined in:
lib/kozo/operations/destroy.rb

Instance Attribute Summary

Attributes inherited from Kozo::Operation

#resource

Instance Method Summary collapse

Methods inherited from Kozo::Operation

#initialize

Constructor Details

This class inherits a constructor from Kozo::Operation

Instance Method Details

#apply(state) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/kozo/operations/destroy.rb', line 9

def apply(state)
  # Destroy resource in remote infrastructure
  resource.destroy!

  # Delete resource from local state
  state.resources.delete(resource)
end

#to_sObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/kozo/operations/destroy.rb', line 17

def to_s
  l = resource.attribute_names.map(&:length).max || 1

  attrs = resource
    .attribute_names
    .map { |k| "  #{display_symbol} r.#{k.to_s.ljust(l)} = #{resource.send(:"#{k}_was").as_s.indent(4)[4..]}" }
    .join("\n")

  <<~DSL.chomp
    #{"# #{resource.address}:".bold}
    #{display_symbol} resource "#{resource.resource_name}", "#{resource.state_name}" do |r|
    #{attrs}
    end

  DSL
end