mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
make more abstract reference to object identity, move reload to base class
This commit is contained in:
parent
e3e826ad69
commit
5affe817f9
3 changed files with 18 additions and 12 deletions
|
@ -4,8 +4,9 @@ module Fog
|
||||||
|
|
||||||
class Bucket < Fog::Model
|
class Bucket < Fog::Model
|
||||||
|
|
||||||
|
identity :name, 'Name'
|
||||||
|
|
||||||
attribute :creation_date, 'CreationDate'
|
attribute :creation_date, 'CreationDate'
|
||||||
attribute :name, 'Name'
|
|
||||||
attribute :owner
|
attribute :owner
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
|
@ -43,11 +44,6 @@ module Fog
|
||||||
@payer = new_payer
|
@payer = new_payer
|
||||||
end
|
end
|
||||||
|
|
||||||
def reload
|
|
||||||
new_attributes = collection.get(@name).attributes
|
|
||||||
merge_attributes(new_attributes)
|
|
||||||
end
|
|
||||||
|
|
||||||
def save
|
def save
|
||||||
options = {}
|
options = {}
|
||||||
if @location
|
if @location
|
||||||
|
|
|
@ -4,11 +4,12 @@ module Fog
|
||||||
|
|
||||||
class Object < Fog::Model
|
class Object < Fog::Model
|
||||||
|
|
||||||
|
identity :key, 'Key'
|
||||||
|
|
||||||
attribute :body
|
attribute :body
|
||||||
attribute :content_length, 'Content-Length'
|
attribute :content_length, 'Content-Length'
|
||||||
attribute :content_type, 'Content-Type'
|
attribute :content_type, 'Content-Type'
|
||||||
attribute :etag, ['Etag', 'ETag']
|
attribute :etag, ['Etag', 'ETag']
|
||||||
attribute :key, 'Key'
|
|
||||||
attribute :last_modified, ['Last-Modified', 'LastModified']
|
attribute :last_modified, ['Last-Modified', 'LastModified']
|
||||||
attribute :owner
|
attribute :owner
|
||||||
attribute :size, 'Size'
|
attribute :size, 'Size'
|
||||||
|
@ -37,11 +38,6 @@ module Fog
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def reload
|
|
||||||
new_attributes = collection.get(@key).attributes
|
|
||||||
merge_attributes(new_attributes)
|
|
||||||
end
|
|
||||||
|
|
||||||
def save(options = {})
|
def save(options = {})
|
||||||
data = connection.put_object(bucket.name, @key, @body, options)
|
data = connection.put_object(bucket.name, @key, @body, options)
|
||||||
@etag = data.headers['ETag']
|
@etag = data.headers['ETag']
|
||||||
|
|
|
@ -11,6 +11,11 @@ module Fog
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.identity(name, other_names = [])
|
||||||
|
@identity = name
|
||||||
|
self.attribute(name, other_names)
|
||||||
|
end
|
||||||
|
|
||||||
def self.aliases
|
def self.aliases
|
||||||
@aliases ||= {}
|
@aliases ||= {}
|
||||||
end
|
end
|
||||||
|
@ -19,6 +24,10 @@ module Fog
|
||||||
@attributes ||= []
|
@attributes ||= []
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def identity
|
||||||
|
send(self.class.instance_variable_get('@identity'))
|
||||||
|
end
|
||||||
|
|
||||||
def initialize(new_attributes = {})
|
def initialize(new_attributes = {})
|
||||||
merge_attributes(new_attributes)
|
merge_attributes(new_attributes)
|
||||||
end
|
end
|
||||||
|
@ -54,6 +63,11 @@ module Fog
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def reload
|
||||||
|
new_attributes = collection.get(identity).attributes
|
||||||
|
merge_attributes(new_attributes)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def collection=(new_collection)
|
def collection=(new_collection)
|
||||||
|
|
Loading…
Add table
Reference in a new issue