Class: Cloudsync::File
- Inherits:
-
Object
- Object
- Cloudsync::File
- Defined in:
- lib/cloudsync/file.rb
Instance Attribute Summary collapse
-
#backend ⇒ Object
Returns the value of attribute backend.
-
#e_tag ⇒ Object
Returns the value of attribute e_tag.
-
#last_modified ⇒ Object
Returns the value of attribute last_modified.
-
#path ⇒ Object
Returns the value of attribute path.
-
#size ⇒ Object
Returns the value of attribute size.
Class Method Summary collapse
- .from_cf_info(container, path, hash, backend) ⇒ Object
- .from_cf_obj(obj, backend = nil) ⇒ Object
- .from_s3_obj(obj, backend = nil) ⇒ Object
Instance Method Summary collapse
- #bucket ⇒ Object (also: #container)
- #download_path ⇒ Object
- #full_download_path ⇒ Object
- #full_name ⇒ Object
- #full_upload_path ⇒ Object
-
#initialize(options = {}) ⇒ File
constructor
A new instance of File.
- #tempfile ⇒ Object
- #to_s ⇒ Object
- #unique_filename ⇒ Object
- #upload_path ⇒ Object
- #upload_path_without_bucket ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ File
Returns a new instance of File.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/cloudsync/file.rb', line 5 def initialize( = {}) @path = [:path] @size = [:size] @last_modified = [:last_modified] @e_tag = [:e_tag] @backend = [:backend] @upload_prefix = [:upload_prefix] @download_prefix = [:download_prefix] @backend_type = [:backend_type] end |
Instance Attribute Details
#backend ⇒ Object
Returns the value of attribute backend.
3 4 5 |
# File 'lib/cloudsync/file.rb', line 3 def backend @backend end |
#e_tag ⇒ Object
Returns the value of attribute e_tag.
3 4 5 |
# File 'lib/cloudsync/file.rb', line 3 def e_tag @e_tag end |
#last_modified ⇒ Object
Returns the value of attribute last_modified.
3 4 5 |
# File 'lib/cloudsync/file.rb', line 3 def last_modified @last_modified end |
#path ⇒ Object
Returns the value of attribute path.
3 4 5 |
# File 'lib/cloudsync/file.rb', line 3 def path @path end |
#size ⇒ Object
Returns the value of attribute size.
3 4 5 |
# File 'lib/cloudsync/file.rb', line 3 def size @size end |
Class Method Details
.from_cf_info(container, path, hash, backend) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/cloudsync/file.rb', line 28 def self.from_cf_info(container, path, hash, backend) new({ :upload_prefix => container.name, :path => path, :size => hash[:bytes], :last_modified => hash[:last_modified].to_gm_time.to_i, :e_tag => hash[:hash], :backend => backend, :backend_type => Cloudsync::Backend::CloudFiles }) end |
.from_cf_obj(obj, backend = nil) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/cloudsync/file.rb', line 39 def self.from_cf_obj(obj, backend=nil) return nil if obj.nil? new({ :upload_prefix => obj.container.name, :path => obj.name, :size => obj.bytes.to_i, :last_modified => obj.last_modified.to_i, :e_tag => obj.etag, :backend => backend, :backend_type => Cloudsync::Backend::CloudFiles}) end |
.from_s3_obj(obj, backend = nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/cloudsync/file.rb', line 16 def self.from_s3_obj(obj, backend=nil) return nil if obj.nil? new({ :upload_prefix => obj.bucket.name, :path => obj.name, :size => obj.size, :last_modified => obj.last_modified.to_i, :e_tag => obj.e_tag.gsub('"',''), :backend => backend, :backend_type => Cloudsync::Backend::S3}) end |
Instance Method Details
#bucket ⇒ Object Also known as: container
63 64 65 66 67 |
# File 'lib/cloudsync/file.rb', line 63 def bucket @bucket ||= begin @upload_prefix.split("/").first end end |
#download_path ⇒ Object
79 80 81 |
# File 'lib/cloudsync/file.rb', line 79 def download_path @download_prefix ? "#{@download_prefix}/#{@path}" : @path end |
#full_download_path ⇒ Object
87 88 89 |
# File 'lib/cloudsync/file.rb', line 87 def full_download_path [bucket, download_path].join("/") end |
#full_name ⇒ Object
59 60 61 |
# File 'lib/cloudsync/file.rb', line 59 def full_name [bucket,path].join("/") end |
#full_upload_path ⇒ Object
91 92 93 |
# File 'lib/cloudsync/file.rb', line 91 def full_upload_path [bucket, upload_path].join("/") end |
#tempfile ⇒ Object
95 96 97 |
# File 'lib/cloudsync/file.rb', line 95 def tempfile Tempfile.new(unique_filename) end |
#to_s ⇒ Object
51 52 53 |
# File 'lib/cloudsync/file.rb', line 51 def to_s "#{full_upload_path}" end |
#unique_filename ⇒ Object
55 56 57 |
# File 'lib/cloudsync/file.rb', line 55 def unique_filename [bucket,e_tag,path].join.gsub(/[^a-zA-Z\-_0-9]/,'') end |
#upload_path ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/cloudsync/file.rb', line 70 def upload_path without_bucket_path = @upload_prefix.sub(/^#{bucket}\/?/,"") if without_bucket_path.empty? @path else without_bucket_path + "/" + @path end end |
#upload_path_without_bucket ⇒ Object
83 84 85 |
# File 'lib/cloudsync/file.rb', line 83 def upload_path_without_bucket end |