Class: Capistrano::Releases::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/capistrano/releases/manager.rb

Overview

Class for pushing/pulling Capistrano releases.

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parameters = {}) ⇒ Manager

Returns a new instance of Manager.



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/capistrano/releases/manager.rb', line 15

def initialize(parameters = {})
  @params = parameters

  params[:bucket] ||=
    defaults[:bucket] || raise('bucket_name is a required parameter')

  params[:deploy_to] ||=
    defaults[:deploy_to] || raise('deploy_to is a required parameter')

  params[:keep_releases] ||=
    (defaults[:keep_releases] || 5)
end

Class Attribute Details

.defaultsObject

Returns the value of attribute defaults.



8
9
10
# File 'lib/capistrano/releases/manager.rb', line 8

def defaults
  @defaults
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



5
6
7
# File 'lib/capistrano/releases/manager.rb', line 5

def params
  @params
end

Instance Method Details

#pullObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/capistrano/releases/manager.rb', line 38

def pull
  make_dirs
  locals = Set.new(local_releases)
  puts "Local releases: #{locals.to_a.inspect}"
  to_download = remote_releases.last(params[:keep_releases])
                               .reject { |r| locals.include?(r) }
  to_download.each do |r|
    puts "Downloading release: #{r}"
    download(r)
  end
  self.local_current = remote_current
  puts "Setting local current to: #{local_current}"
  Dir.chdir(File.join(params[:deploy_to], 'current'))

  to_download
end

#pushObject



28
29
30
31
32
33
34
35
36
# File 'lib/capistrano/releases/manager.rb', line 28

def push
  make_dirs
  remotes = Set.new(remote_releases)
  to_upload = local_releases.reject { |r| remotes.include?(r) }
  to_upload.each { |r| upload(r) }
  self.remote_current = local_current

  to_upload
end