Navigation Menu

Skip to content

Commit

Permalink
added support for Storage::Rackspace::File#metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
pastorius committed Nov 2, 2012
1 parent 5366815 commit 32355ae
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/fog/rackspace/models/storage/file.rb
Expand Up @@ -12,6 +12,7 @@ class File < Fog::Model
attribute :content_type, :aliases => ['content_type', 'Content-Type'] attribute :content_type, :aliases => ['content_type', 'Content-Type']
attribute :etag, :aliases => ['hash', 'Etag'] attribute :etag, :aliases => ['hash', 'Etag']
attribute :last_modified, :aliases => ['last_modified', 'Last-Modified'], :type => :time attribute :last_modified, :aliases => ['last_modified', 'Last-Modified'], :type => :time
attribute :metadata


def body def body
attributes[:body] ||= if last_modified attributes[:body] ||= if last_modified
Expand Down Expand Up @@ -43,6 +44,16 @@ def destroy
true true
end end


remove_method :metadata
def metadata
attributes.reject {|key, value| !metadata_attribute?(key)}
end

remove_method :metadata=
def metadata=(new_metadata)
merge_attributes(new_metadata)
end

def owner=(new_owner) def owner=(new_owner)
if new_owner if new_owner
attributes[:owner] = { attributes[:owner] = {
Expand All @@ -64,8 +75,12 @@ def public_url
def save(options = {}) def save(options = {})
requires :body, :directory, :key requires :body, :directory, :key
options['Content-Type'] = content_type if content_type options['Content-Type'] = content_type if content_type
options.merge!(metadata)
data = connection.put_object(directory.key, key, body, options) data = connection.put_object(directory.key, key, body, options)

merge_attributes(data.headers.reject {|key, value| ['Content-Length', 'Content-Type'].include?(key)}) merge_attributes(data.headers.reject {|key, value| ['Content-Length', 'Content-Type'].include?(key)})
attributes.delete_if {|key, value| metadata_attribute?(key) && value.nil?}

self.content_length = Fog::Storage.get_body_size(body) self.content_length = Fog::Storage.get_body_size(body)
self.content_type ||= Fog::Storage.get_content_type(body) self.content_type ||= Fog::Storage.get_content_type(body)
true true
Expand All @@ -77,6 +92,9 @@ def directory=(new_directory)
@directory = new_directory @directory = new_directory
end end


def metadata_attribute?(key)
key.to_s =~ /^X-Object-Meta-/
end
end end


end end
Expand Down

0 comments on commit 32355ae

Please sign in to comment.