mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[aws|storage] Added the ability to fetch a list of versions from a file.
This commit is contained in:
parent
2d084c7844
commit
a57fdd21dd
3 changed files with 68 additions and 0 deletions
|
@ -1,4 +1,5 @@
|
|||
require 'fog/core/model'
|
||||
require 'fog/aws/models/storage/versions'
|
||||
|
||||
module Fog
|
||||
module Storage
|
||||
|
@ -132,6 +133,15 @@ module Fog
|
|||
collection.get_https_url(key, expires, options)
|
||||
end
|
||||
|
||||
def versions
|
||||
@versions ||= begin
|
||||
Fog::Storage::AWS::Versions.new(
|
||||
:file => self,
|
||||
:connection => connection
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def directory=(new_directory)
|
||||
|
|
24
lib/fog/aws/models/storage/version.rb
Normal file
24
lib/fog/aws/models/storage/version.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module Storage
|
||||
class AWS
|
||||
|
||||
class Version < Fog::Model
|
||||
|
||||
identity :version, :aliases => 'VersionId'
|
||||
|
||||
attribute :key, :aliases => 'Key'
|
||||
attribute :last_modified, :aliases => ['Last-Modified', 'LastModified']
|
||||
attribute :latest, :aliases => 'IsLatest', :type => :boolean
|
||||
attribute :content_length, :aliases => ['Content-Length', 'Size'], :type => :integer
|
||||
attribute :delete_marker, :type => :boolean
|
||||
|
||||
def file
|
||||
@file ||= collection.file.directory.files.get(key, 'versionId' => version)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
34
lib/fog/aws/models/storage/versions.rb
Normal file
34
lib/fog/aws/models/storage/versions.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/aws/models/storage/version'
|
||||
|
||||
module Fog
|
||||
module Storage
|
||||
class AWS
|
||||
|
||||
class Versions < Fog::Collection
|
||||
|
||||
attribute :file
|
||||
|
||||
model Fog::Storage::AWS::Version
|
||||
|
||||
def all
|
||||
data = connection.get_bucket_object_versions(file.directory.key, :prefix => file.key).body['Versions']
|
||||
load(data)
|
||||
end
|
||||
|
||||
def new(attributes = {})
|
||||
requires :file
|
||||
|
||||
version_type = attributes.keys.first
|
||||
|
||||
model = super({ :file => file }.merge!(attributes[version_type]))
|
||||
model.delete_marker = version_type == 'DeleteMarker'
|
||||
|
||||
model
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue