Class: Wordmove::Actions::Ssh::PutDirectory

Inherits:
Object
  • Object
show all
Extended by:
LightService::Action
Includes:
Helpers, Helpers, WordpressDirectory::LocalHelperMethods
Defined in:
lib/wordmove/actions/ssh/put_directory.rb

Overview

Syncs a whole directory over SSH protocol from local host to remote server

Class Method Summary collapse

Class Method Details

.executeLightService::Context

Returns Action’s context.

Parameters:

  • logger (Wordmove::Logger)
  • local_options (Hash)

    Local host options fetched from movefile (with symbolized keys)

  • remote_options (Hash)

    Remote host options fetched from movefile (with symbolized keys)

  • cli_options (Hash)

    Command line options (with symbolized keys)

  • photocopier (Photocopier::SSH)
  • folder_task (Symbol)

    Symbolazied folder name

Returns:

  • (LightService::Context)

    Action’s context



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/wordmove/actions/ssh/put_directory.rb', line 30

executed do |context|
  context.logger.task "Pushing #{context.folder_task}"

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

  command = 'put_directory'
  # For this action `local_path` and `remote_path` will always be
  # `:wordpress_path`; specific folder for `context.folder_task` will be included by
  # `push_include_paths`
  local_path = context.local_options[:wordpress_path]
  remote_path = context.remote_options[:wordpress_path]

  # This action can generate `command_args` by itself,
  # but it gives the context the chance to ovveride it.
  # By the way this variable is not `expects`ed.
  # Note that we do not use the second argument to `fetch`
  # to express a default value, because it would be greedly interpreted
  # but if `command_args` is already defined by context, then it's
  # possible that `"local_#{context.folder_task}_dir"` could
  # not be defined.
  command_args = context.fetch(:command_args) || [
    local_path,
    remote_path,
    push_exclude_paths(
      local_task_dir: send(
        "local_#{context.folder_task}_dir",
        local_options: context.local_options
      ),
      paths_to_exclude: paths_to_exclude(remote_options: context.remote_options)
    ),
    push_include_paths(local_task_dir: send(
      "local_#{context.folder_task}_dir",
      local_options: context.local_options
    ))
  ]

  context.logger.task_step false, "#{command}: #{command_args.join(' ')}"
  result = context.photocopier.send(command, *command_args)

  next context if result == true

  context.fail!("Failed to push #{context.folder_task}")
end