Class: Capistrano::S3Archive::SCM

Inherits:
Capistrano::SCM
  • Object
show all
Includes:
FileUtils
Defined in:
lib/capistrano/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.



24
25
26
27
28
# File 'lib/capistrano/s3_archive.rb', line 24

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.



22
23
24
# File 'lib/capistrano/s3_archive.rb', line 22

def bucket
  @bucket
end

#object_prefixObject

Returns the value of attribute object_prefix.



22
23
24
# File 'lib/capistrano/s3_archive.rb', line 22

def object_prefix
  @object_prefix
end

Instance Method Details

#archive_object_keyObject



55
56
57
58
59
60
61
62
63
# File 'lib/capistrano/s3_archive.rb', line 55

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



30
31
32
33
34
# File 'lib/capistrano/s3_archive.rb', line 30

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



36
37
38
39
40
41
42
# File 'lib/capistrano/s3_archive.rb', line 36

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



44
45
46
47
48
49
50
51
52
53
# File 'lib/capistrano/s3_archive.rb', line 44

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