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

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

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.



156
157
158
# File 'lib/bovem/shell.rb', line 156

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

#copy_or_move(src, dst, operation, run = true, show_errors = false, fatal = true) ⇒ Boolean

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: false)

    If show errors.

  • fatal (Boolean) (defaults to: true)

    If quit in case of fatal errors.

Returns:

  • (Boolean)

    true if operation succeeded, false otherwise.



181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/bovem/shell.rb', line 181

def copy_or_move(src, dst, operation, run = true, show_errors = false, fatal = true)        
  rv = true
  locale = self.i18n.shell
  operation, operation_s, single, src, dst = sanitize_copy_or_move_arguments(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

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

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.



168
169
170
# File 'lib/bovem/shell.rb', line 168

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