Parent

Class/Module Index [+]

Quicksearch

Fog::Storage::Rackspace::Mock::MockObject

An in-memory Swift object.

Attributes

body[R]
bytes_used[R]
content_type[R]
hash[R]
last_modified[R]
meta[R]
service[R]
static_manifest[RW]

Public Class Methods

new(data, service) click to toggle source

Construct a new object. Generally, you should call {MockContainer#add_object} instead of instantiating these directly.

# 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

Public Instance Methods

dynamic_manifest?() click to toggle source

Determine if this object has the metadata header that marks it as a dynamic large object manifest.

@return [Boolean]

# File lib/fog/rackspace/storage.rb, line 237
def dynamic_manifest?
  ! large_object_prefix.nil?
end
each_part() click to toggle source

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.

@yield [MockObject] Each object that holds a part of this logical

object.
# 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() click to toggle source

Access the object name prefix that controls which other objects comprise a dynamic large object.

@return [String, nil] The object name prefix, or `nil` if none is

present.
# File lib/fog/rackspace/storage.rb, line 300
def large_object_prefix
  @meta['X-Object-Manifest']
end
static_manifest?() click to toggle source

Determine if this object was created as a static large object manifest.

@return [Boolean]

# File lib/fog/rackspace/storage.rb, line 229
def static_manifest?
  @static_manifest
end
to_headers() click to toggle source

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.

@return [Hash<String, String>] Header values stored in a Hash.

# 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

[Validate]

Generated with the Darkfish Rdoc Generator 2.