Class: CloudSync::Resource
- Inherits:
-
Object
- Object
- CloudSync::Resource
- Defined in:
- lib/cloud_sync/resource.rb
Instance Attribute Summary collapse
-
#medium ⇒ Object
Returns the value of attribute medium.
-
#path ⇒ Object
Returns the value of attribute path.
-
#type ⇒ Object
Returns the value of attribute type.
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
- #copy(to) ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(uri) ⇒ Resource
constructor
A new instance of Resource.
- #reader ⇒ Object
- #writer ⇒ Object
Constructor Details
#initialize(uri) ⇒ Resource
Returns a new instance of Resource.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/cloud_sync/resource.rb', line 13 def initialize uri raise "Invalid resource string #{uri}" unless uri =~ /\w+:/ @uri = uri @type, @path = uri.split(":") @type = @type.to_sym raise "Invalid medium type: #{@type}" unless MediaTypes.has_key?(@type) @medium = MediaTypes[@type].new end |
Instance Attribute Details
#medium ⇒ Object
Returns the value of attribute medium.
11 12 13 |
# File 'lib/cloud_sync/resource.rb', line 11 def medium @medium end |
#path ⇒ Object
Returns the value of attribute path.
11 12 13 |
# File 'lib/cloud_sync/resource.rb', line 11 def path @path end |
#type ⇒ Object
Returns the value of attribute type.
11 12 13 |
# File 'lib/cloud_sync/resource.rb', line 11 def type @type end |
#uri ⇒ Object
Returns the value of attribute uri.
11 12 13 |
# File 'lib/cloud_sync/resource.rb', line 11 def uri @uri end |
Instance Method Details
#copy(to) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/cloud_sync/resource.rb', line 29 def copy to raise "Resource #{@uri} does not exist" unless exists? input = reader output = to.writer output.write(input.read) input.close if input.respond_to? :close output.close if output.respond_to? :close end |
#exists? ⇒ Boolean
25 26 27 |
# File 'lib/cloud_sync/resource.rb', line 25 def exists? @medium.exists?(@path) end |
#reader ⇒ Object
45 46 47 |
# File 'lib/cloud_sync/resource.rb', line 45 def reader @medium.reader @path end |
#writer ⇒ Object
41 42 43 |
# File 'lib/cloud_sync/resource.rb', line 41 def writer @medium.writer @path end |