Class: IMW::Tools::Transferer

Inherits:
Object
  • Object
show all
Defined in:
lib/imw/tools/transferer.rb

Overview

A class to encapsulate transferring a resource from one URI to another.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action, source, destination) ⇒ Transferer

Instantiate a new transferer to take the given action on source and destination.

Parameters:

Raises:



65
66
67
68
69
70
# File 'lib/imw/tools/transferer.rb', line 65

def initialize action, source, destination
  self.action      = action
  self.source      = source
  self.destination = destination
  raise IMW::PathError.new("Source and destination have the same URI: #{source}") if self.source.uri.to_s == self.destination.uri.to_s
end

Instance Attribute Details

#action:cp, :mv

The action this Transferer is to take.

Returns:

  • (:cp, :mv)


11
12
13
# File 'lib/imw/tools/transferer.rb', line 11

def action
  @action
end

#destinationIMW::Resource

The destination resource.

Returns:



47
48
49
# File 'lib/imw/tools/transferer.rb', line 47

def destination
  @destination
end

#sourceIMW::Resource

The source resource.

Returns:



30
31
32
# File 'lib/imw/tools/transferer.rb', line 30

def source
  @source
end

Instance Method Details

#transfer!Object

Transfer source to destination.

For local transfer, will raise errors unless the necessary paths exist.



76
77
78
79
80
# File 'lib/imw/tools/transferer.rb', line 76

def transfer!
  IMW.announce_if_verbose("#{action_gerund.capitalize} #{source} to #{destination}")
  send(transfer_method)
  destination.reopen
end