Class: Fog::Storage::Dtdream::Files
- Inherits:
-
Collection
- Object
- Collection
- Fog::Storage::Dtdream::Files
- Defined in:
- lib/fog/dtdream/models/storage/files.rb
Instance Method Summary collapse
- #all(options = {}) ⇒ Object
- #each ⇒ Object
- #each_file_this_page ⇒ Object
- #get(key, &block) ⇒ Object
- #get_http_url(key, expires, options = {}) ⇒ Object
- #get_https_url(key, expires, options = {}) ⇒ Object
- #get_url(key) ⇒ Object
- #head(key, options = {}) ⇒ Object
- #new(attributes = {}) ⇒ Object
Instance Method Details
#all(options = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/fog/dtdream/models/storage/files.rb', line 16 def all( = {}) requires :directory if directory.key != "" && directory.key != "." && directory.key != nil prefix = directory.key+"/" end files = service.list_objects({:prefix => prefix})["Contents"] if nil == files return end data = Array.new i = 0 files.each do |file| if file["Key"][0][-1] != "/" content_length = file["Size"][0].to_i key = file["Key"][0] lastModified = file["LastModified"][0] if lastModified != nil && lastModified != "" last_modified = (Time.parse(lastModified)).localtime else last_modified = nil end data[i] = {:content_length => content_length, :key => key, :last_modified => last_modified, :etag => file["ETag"][0]} i = i + 1 end end load(data) end |
#each ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/fog/dtdream/models/storage/files.rb', line 50 def each if !block_given? self else subset = dup.all subset.each_file_this_page {|f| yield f} while subset.length == (subset.limit || 10000) subset = subset.all(:marker => subset.last.key) subset.each_file_this_page {|f| yield f} end self end end |
#each_file_this_page ⇒ Object
49 |
# File 'lib/fog/dtdream/models/storage/files.rb', line 49 alias_method :each_file_this_page, :each |
#get(key, &block) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/fog/dtdream/models/storage/files.rb', line 66 def get(key, &block) requires :directory if directory.key == "" object = key else object = directory.key+"/"+key end data = service.head_object(object).data contentLen = data[:headers]["Content-Length"].to_i if data[:status] != 200 return nil end lastModified = data[:headers]["Last-Modified"] if lastModified != nil && lastModified != "" last_modified = (Time.parse(lastModified)).localtime else last_modified = nil end file_data = { :content_length => contentLen, :key => key, :last_modified => last_modified, :content_type => data[:headers]["Content-Type"], :etag => data[:headers]["ETag"] } if block_given? pagesNum = (contentLen + Excon::CHUNK_SIZE - 1)/Excon::CHUNK_SIZE for i in 1..pagesNum _start = (i-1)*(Excon::CHUNK_SIZE) _end = i*(Excon::CHUNK_SIZE) - 1 range = "#{_start}-#{_end}" chunk = service.get_object(object, range)[:body] yield(chunk) end new(file_data) else data = service.get_object(object) file_data.merge!(:body => data[:body]) new(file_data) end end |
#get_http_url(key, expires, options = {}) ⇒ Object
124 125 126 127 128 129 130 131 132 |
# File 'lib/fog/dtdream/models/storage/files.rb', line 124 def get_http_url(key, expires, = {}) requires :directory if directory.key == "" object = key else object = directory.key+"/"+key end service.get_object_http_url_public(object, expires, ) end |
#get_https_url(key, expires, options = {}) ⇒ Object
134 135 136 137 138 139 140 141 142 |
# File 'lib/fog/dtdream/models/storage/files.rb', line 134 def get_https_url(key, expires, = {}) requires :directory if directory.key == "" object = key else object = directory.key+"/"+key end service.get_object_https_url_public(object, expires, ) end |
#get_url(key) ⇒ Object
114 115 116 117 118 119 120 121 122 |
# File 'lib/fog/dtdream/models/storage/files.rb', line 114 def get_url(key) requires :directory if directory.key == "" object = key else object = directory.key+"/"+key end service.get_object_http_url_public(object, 3600) end |
#head(key, options = {}) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/fog/dtdream/models/storage/files.rb', line 144 def head(key, = {}) requires :directory if directory.key == "" object = key else object = directory.key+"/"+key end data = service.head_object(object).data lastModified = data[:headers]["Last-Modified"] if lastModified != nil && lastModified != "" last_modified = (Time.parse(lastModified)).localtime else last_modified = nil end file_data = { :content_length => data[:headers]["Content-Length"].to_i, :key => key, :last_modified => last_modified, :content_type => data[:headers]["Content-Type"], :etag => data[:headers]["ETag"] } new(file_data) rescue Fog::Storage::Dtdream::NotFound nil end |
#new(attributes = {}) ⇒ Object
171 172 173 174 |
# File 'lib/fog/dtdream/models/storage/files.rb', line 171 def new(attributes = {}) requires :directory super({ :directory => directory }.merge!(attributes)) end |