Class: Fog::Storage::Rackspace::Mock::MockObject
- Inherits:
-
Object
- Object
- Fog::Storage::Rackspace::Mock::MockObject
- Defined in:
- lib/fog/rackspace/storage.rb
Overview
An in-memory Swift object.
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#bytes_used ⇒ Object
readonly
Returns the value of attribute bytes_used.
-
#content_type ⇒ Object
readonly
Returns the value of attribute content_type.
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
-
#last_modified ⇒ Object
readonly
Returns the value of attribute last_modified.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#service ⇒ Object
readonly
Returns the value of attribute service.
-
#static_manifest ⇒ Object
Returns the value of attribute static_manifest.
Instance Method Summary collapse
-
#dynamic_manifest? ⇒ Boolean
Determine if this object has the metadata header that marks it as a dynamic large object manifest.
-
#each_part {|MockObject| ... } ⇒ Object
Iterate through each MockObject that contains a part of the data for this logical object.
-
#initialize(data, service) ⇒ MockObject
constructor
Construct a new object.
-
#large_object_prefix ⇒ String?
Access the object name prefix that controls which other objects comprise a dynamic large object.
-
#static_manifest? ⇒ Boolean
Determine if this object was created as a static large object manifest.
-
#to_headers ⇒ Hash<String, String>
Construct the fake HTTP headers that should be returned on requests targetting this object.
Constructor Details
#initialize(data, service) ⇒ MockObject
Construct a new object. Generally, you should call Fog::Storage::Rackspace::Mock::MockContainer#add_object instead of instantiating these directly.
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/fog/rackspace/storage.rb', line 208 def initialize(data, service) data = Fog::Storage.parse_data(data) @service = service @bytes_used = data[:headers]['Content-Length'] @content_type = data[:headers]['Content-Type'] if data[:body].respond_to? :read @body = data[:body].read else @body = data[:body] end @last_modified = Time.now.utc @hash = Digest::MD5.hexdigest(@body) @meta = {} @static_manifest = false end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
203 204 205 |
# File 'lib/fog/rackspace/storage.rb', line 203 def body @body end |
#bytes_used ⇒ Object (readonly)
Returns the value of attribute bytes_used.
202 203 204 |
# File 'lib/fog/rackspace/storage.rb', line 202 def bytes_used @bytes_used end |
#content_type ⇒ Object (readonly)
Returns the value of attribute content_type.
202 203 204 |
# File 'lib/fog/rackspace/storage.rb', line 202 def content_type @content_type end |
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
202 203 204 |
# File 'lib/fog/rackspace/storage.rb', line 202 def hash @hash end |
#last_modified ⇒ Object (readonly)
Returns the value of attribute last_modified.
202 203 204 |
# File 'lib/fog/rackspace/storage.rb', line 202 def last_modified @last_modified end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
203 204 205 |
# File 'lib/fog/rackspace/storage.rb', line 203 def @meta end |
#service ⇒ Object (readonly)
Returns the value of attribute service.
203 204 205 |
# File 'lib/fog/rackspace/storage.rb', line 203 def service @service end |
#static_manifest ⇒ Object
Returns the value of attribute static_manifest.
204 205 206 |
# File 'lib/fog/rackspace/storage.rb', line 204 def static_manifest @static_manifest end |
Instance Method Details
#dynamic_manifest? ⇒ Boolean
Determine if this object has the metadata header that marks it as a dynamic large object manifest.
237 238 239 |
# File 'lib/fog/rackspace/storage.rb', line 237 def dynamic_manifest? ! large_object_prefix.nil? end |
#each_part {|MockObject| ... } ⇒ Object
Iterate through each MockObject that contains a part of the data for this logical object. In the normal case, this will only yield the receiver directly. For dynamic and static large object manifests, however, this call will yield each MockObject that contains a part of the whole, in sequence.
Manifests that refer to containers or objects that don’t exist will skip those sections and log a warning, instead.
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
# File 'lib/fog/rackspace/storage.rb', line 252 def each_part case when dynamic_manifest? # Concatenate the contents and sizes of each matching object. # Note that cname and oprefix are already escaped. cname, oprefix = large_object_prefix.split('/', 2) target_container = service.data[cname] if target_container all = target_container.objects.keys matching = all.select { |name| name.start_with? oprefix } keys = matching.sort keys.each do |name| yield target_container.objects[name] end else Fog::Logger.warning "Invalid container in dynamic object manifest: #{cname}" yield self end when static_manifest? Fog::JSON.decode(body).each do |segment| cname, oname = segment['path'].split('/', 2) cont = service.mock_container cname unless cont Fog::Logger.warning "Invalid container in static object manifest: #{cname}" next end obj = cont.mock_object oname unless obj Fog::Logger.warning "Invalid object in static object manifest: #{oname}" next end yield obj end else yield self end end |
#large_object_prefix ⇒ String?
Access the object name prefix that controls which other objects comprise a dynamic large object.
300 301 302 |
# File 'lib/fog/rackspace/storage.rb', line 300 def large_object_prefix @meta['X-Object-Manifest'] end |
#static_manifest? ⇒ Boolean
Determine if this object was created as a static large object manifest.
229 230 231 |
# File 'lib/fog/rackspace/storage.rb', line 229 def static_manifest? @static_manifest end |
#to_headers ⇒ Hash<String, String>
Construct the fake HTTP headers that should be returned on requests targetting this object. Includes computed ‘Content-Type`, `Content-Length`, `Last-Modified` and `ETag` headers in addition to whatever metadata has been associated with this object manually.
310 311 312 313 314 315 316 317 |
# File 'lib/fog/rackspace/storage.rb', line 310 def to_headers { 'Content-Type' => @content_type, 'Content-Length' => @bytes_used, 'Last-Modified' => @last_modified.strftime('%a, %b %d %Y %H:%M:%S %Z'), 'ETag' => @hash }.merge(@meta) end |