Module: Bovem::ShellMethods::Write

Included in:
Bovem::Shell
Defined in:
lib/bovem/shell.rb

Overview

Methods to copy or move entries.

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) copy(src, dst, run = true, show_errors = false, fatal = true)

Copies a set of files or directory to another location.

Parameters:

  • src (String|Array)

    The entries to copy. If is an Array, dst is assumed to be a directory.

  • dst (String)

    The destination. Any existing entries will be overwritten. Any required directory will be created.

  • run (Boolean) (defaults to: true)

    If false, it will just print a list of message that would be copied or moved.

  • show_errors (Boolean) (defaults to: false)

    If show errors.

  • fatal (Boolean) (defaults to: true)

    If quit in case of fatal errors.

Returns:

  • (Boolean)

    true if operation succeeded, false otherwise.



163
164
165
# File 'lib/bovem/shell.rb', line 163

def copy(src, dst, run = true, show_errors = false, fatal = true)
  copy_or_move(src, dst, :copy, run, show_errors, fatal)
end

- (Boolean) copy_or_move(src, dst, operation, run = true, show_errors = true, fatal = true)

Copies or moves a set of files or directory to another location.

Parameters:

  • src (String|Array)

    The entries to copy or move. If is an Array, dst is assumed to be a directory.

  • dst (String)

    The destination. Any existing entries will be overwritten. Any required directory will be created.

  • operation (Symbol)

    The operation to perform. Valid values are :copy or :move.

  • run (Boolean) (defaults to: true)

    If false, it will just print a list of message that would be copied or moved.

  • show_errors (Boolean) (defaults to: true)

    If show errors.

  • fatal (Boolean) (defaults to: true)

    If quit in case of fatal errors.

Returns:

  • (Boolean)

    true if operation succeeded, false otherwise.



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/bovem/shell.rb', line 188

def copy_or_move(src, dst, operation, run = true, show_errors = true, fatal = true)
  rv = true
  operation, operation_s, single, src, dst = sanitize_copy_or_move(operation, src, dst)

  if !run then
    dry_run_copy_or_move(single, operation_s, src, dst)
  else
    rv = catch(:rv) do
      dst_dir = prepare_destination(single, src, dst, operation_s, show_errors, fatal)
      check_sources(src, operation_s, fatal)
      execute_copy_or_move(src, dst, dst_dir, single, operation, operation_s, show_errors, fatal)
      true
    end
  end

  rv
end

- (Boolean) move(src, dst, run = true, show_errors = false, fatal = true)

Moves a set of files or directory to another location.

Parameters:

  • src (String|Array)

    The entries to move. If is an Array, dst is assumed to be a directory.

  • dst (String)

    The destination. Any existing entries will be overwritten. Any required directory will be created.

  • run (Boolean) (defaults to: true)

    If false, it will just print a list of message that would be deleted.

  • show_errors (Boolean) (defaults to: false)

    If show errors.

  • fatal (Boolean) (defaults to: true)

    If quit in case of fatal errors.

Returns:

  • (Boolean)

    true if operation succeeded, false otherwise.



175
176
177
# File 'lib/bovem/shell.rb', line 175

def move(src, dst, run = true, show_errors = false, fatal = true)
  copy_or_move(src, dst, :move, run, show_errors, fatal)
end