lib/defog/handle.rb in defog-0.8.0 vs lib/defog/handle.rb in defog-0.9.0
- old
+ new
@@ -12,23 +12,23 @@
# defog.file("key/to/my/file") do |handle|
# # ... access the proxy handle ...
# end
#
# The #proxy_path attribute method returns a <code>Pathname</code>
- # giving the local proxy file location. Querying the attribute does
+ # giving the local proxy file location. Querying the attribute does
# <i>not</i> upload, download, synchronize, or otherwise interact with
# the cloud or local proxy file in any way -- it just returns a constructed
# Pathname. The <code>proxy_path</code> is a deterministic function of the
# cloud key and Defog::Proxy#proxy_root, so you can rely on it not
# changing between independent accesses to a cloud file.
- #
+ #
class Handle
attr_reader :key
attr_reader :proxy #:nodoc:
- # Pathname where proxy file is, was, or will be located.
+ # Pathname where proxy file is, was, or will be located.
attr_reader :proxy_path
def initialize(proxy, key) #:nodoc:
@proxy = proxy
@key = key
@@ -37,11 +37,11 @@
def to_s
"<#{self.class}: key=#{key}>"
end
- # Returns true if the remote cloud file exists
+ # Returns true if the remote cloud file exists
def exist?
!!fog_model
end
# Deletes the remote cloud file if it exists
@@ -51,17 +51,24 @@
# Returns the size of the remote cloud file, or nil if it doesn't exist
def size
fog_model.andand.content_length
end
-
+
# Returns the modification date of the remote cloud file, or nil if it
# doesn't exist
def last_modified
fog_model.andand.last_modified
end
+ # Returns the MD5 hash digest of the remote cloud file, or nil if it
+ # doesn't exist
+ #
+ def md5_hash
+ return @proxy.fog_wrapper.get_md5(@key) if exist?
+ end
+
# Returns a URL to access the remote cloud file. The options are
# storage-specific.
#
# For :AWS files, the option
# :expiry => time
@@ -73,11 +80,11 @@
# :query => {'response-content-disposition' => 'attachment'}
#
# For :local cloud files, all options are ignored. If Rails is defined
# and the file is in Rails app's public directory, returns a path
# relative to the public directory. Otherwise returns a
- # <code>"file://"</code> URL
+ # <code>"file://"</code> URL
def url(opts={})
opts = opts.keyword_args(:expiry => Time.now + 10*60, :query => :optional)
@proxy.fog_wrapper.url(@key, opts)
end
@@ -89,10 +96,10 @@
# handle.fog_model.key == defog.prefix + handle.key
def fog_model
@proxy.fog_wrapper.fog_head(@key)
end
- # Returns a Defog::File object, which is a specialization of ::File.
+ # Returns a Defog::File object, which is a specialization of ::File.
#
# <code>mode</code> can be the usual "r", "r+", "w", "w+", "a", or "a+" with the
# usual semantics. When opened in a readable mode ("r", "r+", "w+",
# "a+"), first caches the cloud file in the local proxy. When opened
# in a writeable mode ("r+", "w", "w+", "a", "a+"), arranges to upload