Class: IMW::Tools::Transferer
- Inherits:
-
Object
- Object
- IMW::Tools::Transferer
- Defined in:
- lib/imw/tools/transferer.rb
Overview
A class to encapsulate transferring a resource from one URI to another.
Instance Attribute Summary collapse
-
#action ⇒ :cp, :mv
The action this Transferer is to take.
-
#destination ⇒ IMW::Resource
The destination resource.
-
#source ⇒ IMW::Resource
The source resource.
Instance Method Summary collapse
-
#initialize(action, source, destination) ⇒ Transferer
constructor
Instantiate a new transferer to take the given
action
onsource
anddestination
. -
#transfer! ⇒ Object
Transfer source to destination.
Constructor Details
#initialize(action, source, destination) ⇒ Transferer
Instantiate a new transferer to take the given action
on source
and destination
.
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.
11 12 13 |
# File 'lib/imw/tools/transferer.rb', line 11 def action @action end |
#destination ⇒ IMW::Resource
The destination resource.
47 48 49 |
# File 'lib/imw/tools/transferer.rb', line 47 def destination @destination end |
#source ⇒ IMW::Resource
The source resource.
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 |