Class: Capistrano::SCM::S3Archive::ArchiveObject
- Inherits:
-
Object
- Object
- Capistrano::SCM::S3Archive::ArchiveObject
- Defined in:
- lib/capistrano/scm/s3_archive/archive_object.rb
Instance Attribute Summary collapse
-
#branch ⇒ Object
readonly
Returns the value of attribute branch.
-
#bucket ⇒ Object
readonly
Returns the value of attribute bucket.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#sort_proc ⇒ Object
readonly
Returns the value of attribute sort_proc.
-
#version_id ⇒ Object
readonly
Returns the value of attribute version_id.
Instance Method Summary collapse
- #check_access! ⇒ Object
- #current_revision ⇒ Object
- #etag ⇒ Object
- #get_object(io) ⇒ Object
-
#initialize(repo_url: nil, version_id: nil, sort_proc: nil, branch: :latest, client_options: {}) ⇒ ArchiveObject
constructor
A new instance of ArchiveObject.
- #key ⇒ Object
- #key_basename ⇒ Object
- #latest_key ⇒ Object
- #list_all_objects ⇒ Object
- #metadata ⇒ Object
Constructor Details
#initialize(repo_url: nil, version_id: nil, sort_proc: nil, branch: :latest, client_options: {}) ⇒ ArchiveObject
Returns a new instance of ArchiveObject.
10 11 12 13 14 15 16 17 18 |
# File 'lib/capistrano/scm/s3_archive/archive_object.rb', line 10 def initialize(repo_url: nil, version_id: nil, sort_proc: nil, branch: :latest, client_options: {}) uri = URI.parse(repo_url) @bucket = uri.host @prefix = uri.path.sub(%r{/?\Z}, '/').slice(1..-1) # normalize path @version_id = version_id @sort_proc = sort_proc @branch = branch @client = Aws::S3::Client.new() end |
Instance Attribute Details
#branch ⇒ Object (readonly)
Returns the value of attribute branch.
8 9 10 |
# File 'lib/capistrano/scm/s3_archive/archive_object.rb', line 8 def branch @branch end |
#bucket ⇒ Object (readonly)
Returns the value of attribute bucket.
8 9 10 |
# File 'lib/capistrano/scm/s3_archive/archive_object.rb', line 8 def bucket @bucket end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
8 9 10 |
# File 'lib/capistrano/scm/s3_archive/archive_object.rb', line 8 def client @client end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
8 9 10 |
# File 'lib/capistrano/scm/s3_archive/archive_object.rb', line 8 def prefix @prefix end |
#sort_proc ⇒ Object (readonly)
Returns the value of attribute sort_proc.
8 9 10 |
# File 'lib/capistrano/scm/s3_archive/archive_object.rb', line 8 def sort_proc @sort_proc end |
#version_id ⇒ Object (readonly)
Returns the value of attribute version_id.
8 9 10 |
# File 'lib/capistrano/scm/s3_archive/archive_object.rb', line 8 def version_id @version_id end |
Instance Method Details
#check_access! ⇒ Object
20 21 22 |
# File 'lib/capistrano/scm/s3_archive/archive_object.rb', line 20 def check_access! client.list_objects(bucket: bucket, prefix: prefix) end |
#current_revision ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/capistrano/scm/s3_archive/archive_object.rb', line 52 def current_revision if version_id "#{key}?versionid=#{version_id}" else key end end |
#etag ⇒ Object
48 49 50 |
# File 'lib/capistrano/scm/s3_archive/archive_object.rb', line 48 def etag .tap { |it| raise "No such object: #{current_revision}" if it.nil? }.etag end |
#get_object(io) ⇒ Object
68 69 70 71 72 |
# File 'lib/capistrano/scm/s3_archive/archive_object.rb', line 68 def get_object(io) = { bucket: bucket, key: key } [:version_id] = version_id if version_id client.get_object(, target: io) end |
#key ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/capistrano/scm/s3_archive/archive_object.rb', line 24 def key @key ||= case branch.to_sym when :master, :latest latest_key else prefix + branch.to_s end end |
#key_basename ⇒ Object
33 34 35 |
# File 'lib/capistrano/scm/s3_archive/archive_object.rb', line 33 def key_basename File.basename(key) end |
#latest_key ⇒ Object
37 38 39 |
# File 'lib/capistrano/scm/s3_archive/archive_object.rb', line 37 def latest_key list_all_objects.min(&sort_proc).key end |
#list_all_objects ⇒ Object
41 42 43 44 45 46 |
# File 'lib/capistrano/scm/s3_archive/archive_object.rb', line 41 def list_all_objects response = client.list_objects(bucket: bucket, prefix: prefix) response.inject([]) do |objects, page| objects + page.contents end end |
#metadata ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/capistrano/scm/s3_archive/archive_object.rb', line 60 def client.list_object_versions(bucket: bucket, prefix: key).versions.find do |v| if version_id then v.version_id == version_id else v.is_latest end end end |