Class: Wordmove::Actions::PutFile

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

Overview

Note:

The remote server is already configured inside the Photocopier object

Note:

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

Upload a single file to the remote server.

Instance Method Summary collapse

Instance Method Details

#executeLightService::Context

Returns Action’s context.

Parameters:

  • photocopier (Photocopier)
  • logger (Wordmove::Logger)
  • command_args ((String) local file path, (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
41
42
43
44
45
# File 'lib/wordmove/actions/put_file.rb', line 21

executed do |context|
  command = 'put'

  # First argument could be a file or a content string. Do not log if the latter
  message = if File.exist?(context.command_args.first)
              context.command_args.join(' ')
            else
              context.command_args.second
            end

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

  result = simulate?(cli_options: context.cli_options) ||
           context.photocopier.send(
             command,
             *context.command_args
           )

  next context if result == true
  # We can't trust the return from the fotocopier method when using FTP.  Keep on
  # and have faith.
  next context if context.photocopier.is_a? Photocopier::FTP

  context.fail! "Failed to upload file: #{context.command_args.first}"
end