Class: Capistrano::S3Archive::SCM

Inherits:
Capistrano::SCM show all
Includes:
FileUtils
Defined in:
lib/capistrano/legacy_s3_archive.rb

Defined Under Namespace

Modules: RsyncStrategy

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ SCM

Returns a new instance of SCM.



26
27
28
29
30
# File 'lib/capistrano/legacy_s3_archive.rb', line 26

def initialize(*args)
  super
  @bucket, @object_prefix = parse_s3_uri(repo_url)
  set :local_cache_dir, "#{fetch(:local_cache)}/#{fetch(:stage)}"
end

Instance Attribute Details

#bucketObject

Returns the value of attribute bucket.



24
25
26
# File 'lib/capistrano/legacy_s3_archive.rb', line 24

def bucket
  @bucket
end

#object_prefixObject

Returns the value of attribute object_prefix.



24
25
26
# File 'lib/capistrano/legacy_s3_archive.rb', line 24

def object_prefix
  @object_prefix
end

Instance Method Details

#archive_object_keyObject



57
58
59
60
61
62
63
64
65
# File 'lib/capistrano/legacy_s3_archive.rb', line 57

def archive_object_key
  @archive_object_key ||=
    case fetch(:branch).to_sym
    when :master, :latest, nil
      latest_object_key
    else
      object_prefix + fetch(:branch)
    end
end

#get_object(target) ⇒ Object



32
33
34
35
36
# File 'lib/capistrano/legacy_s3_archive.rb', line 32

def get_object(target)
  opts = { bucket: bucket, key: archive_object_key }
  opts[:version_id] = fetch(:version_id) if fetch(:version_id)
  s3_client.get_object(opts, target: target)
end

#get_object_metadataObject



38
39
40
41
42
43
44
# File 'lib/capistrano/legacy_s3_archive.rb', line 38

def 
  s3_client.list_object_versions(bucket: bucket, prefix: archive_object_key).versions.find do |v|
    if fetch(:version_id) then v.version_id == fetch(:version_id)
    else v.is_latest
    end
  end
end

#list_objects(all_page = true) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/capistrano/legacy_s3_archive.rb', line 46

def list_objects(all_page = true)
  response = s3_client.list_objects(bucket: bucket, prefix: object_prefix)
  if all_page
    response.inject([]) do |objects, page|
      objects += page.contents
    end
  else
    response
  end
end