Class: Wordmove::Actions::DeleteRemoteFile

Inherits:
Object
  • Object
show all
Extended by:
LightService::Action
Includes:
Helpers
Defined in:
lib/wordmove/actions/delete_remote_file.rb

Overview

Note:

This action is not meant to be organized, but as a standalone one.

Delete a remote file

Class Method Summary collapse

Class Method Details

.executeLightService::Context

Returns Action’s context.

Parameters:

  • photocopier (Photocopier)
  • logger (Wordmove::Logger)
  • cli_options (Hash)

    Command line options (with symbolized keys)

  • remote_file ((String) remote file path)

Returns:

  • (LightService::Context)

    Action’s context



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/wordmove/actions/delete_remote_file.rb', line 21

executed do |context|
  command = 'delete'

  context.logger.task_step false, "#{command}: #{context.remote_file}"

  next context if simulate?(cli_options: context.cli_options)

  _stdout, stderr, exit_code = context.photocopier.send(command, context.remote_file)

  next context if exit_code&.zero?

  # When +context.photocopier+ is a +Photocopier::FTP+ instance, +delte+ will always
  # return +nil+; so it's impossible to correctly fail the context when using
  # FTP protocol. The problem is how +Net::FTP+ ruby class behaves.
  # IMO this is an acceptable tradeoff.
  unless exit_code.nil?
    context.fail! "Error code #{exit_code} returned while deleting file " \
                  "#{context.remote_file}: #{stderr}"
  end
end