Class: Kozo::Commands::State::Delete

Inherits:
Kozo::Commands::State show all
Defined in:
lib/kozo/commands/state/delete.rb

Instance Attribute Summary collapse

Attributes inherited from Kozo::Commands::State

#subcommand

Attributes inherited from Kozo::Command

#args, #configuration

Instance Method Summary collapse

Constructor Details

#initialize(configuration, *args) ⇒ Delete

Returns a new instance of Delete.

Raises:



11
12
13
14
15
16
# File 'lib/kozo/commands/state/delete.rb', line 11

def initialize(configuration, *args)
  @configuration = configuration
  @address = args.shift

  raise UsageError, "address not specified" unless address
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



9
10
11
# File 'lib/kozo/commands/state/delete.rb', line 9

def address
  @address
end

Instance Method Details

#startObject

Raises:



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/kozo/commands/state/delete.rb', line 18

def start
  resource = state
    .resources
    .find { |r| r.address == address }

  raise StateError, "no such resource address: #{address}" unless resource

  state
    .resources
    .delete_if { |r| r.address == address }

  Kozo.logger.info resource.address

  # Write state
  configuration
    .backend
    .state = state
end