Class: Geordi::CapistranoConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/geordi/capistrano_config.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stage) ⇒ CapistranoConfig

Returns a new instance of CapistranoConfig.



6
7
8
9
10
# File 'lib/geordi/capistrano_config.rb', line 6

def initialize(stage)
  self.stage = stage
  self.root = find_project_root!
  load_deploy_info
end

Instance Attribute Details

#rootObject

Returns the value of attribute root.



4
5
6
# File 'lib/geordi/capistrano_config.rb', line 4

def root
  @root
end

Class Method Details

.current_app_revisions(target_stage) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/geordi/capistrano_config.rb', line 54

def self.current_app_revisions(target_stage)
  return ['a76fdd46e5319a202f7daa3f0fbdadb0c6f44408'] if Util.testing?
  output = `cap #{target_stage} app:revision`

  # git revisions are in SHA-1 format => 40-byte hexadecimal string
  output.scan(/[a-f0-9]{40}/).uniq
end

.task_defined?(task_name) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
65
# File 'lib/geordi/capistrano_config.rb', line 62

def self.task_defined?(task_name)
  return true if Util.testing?
  `cap -T`.split.include?(task_name)
end

Instance Method Details

#branchObject



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/geordi/capistrano_config.rb', line 21

def branch
  deploy_info[/
    # Marker
    ^\s*set.:branch,

    # Might be followed by ENV['DEPLOY_BRANCH']
    .*

    # Assume the last word in quotes will be the right branch
    # (\1 matches the opening quote character)
    (['"])(\w+)\1\s*$
  /x, 2]
end

#envObject



46
47
48
# File 'lib/geordi/capistrano_config.rb', line 46

def env
  deploy_info[/^\s*set\s*:rails_env,\s*['"](.*?)['"]/, 1]
end

#primary_serverObject



35
36
37
38
39
40
# File 'lib/geordi/capistrano_config.rb', line 35

def primary_server
  # Actually, servers may have a :primary property. From Capistrano 3, the
  # first listed server is the primary one by default, which is a good-
  # enough default for us.
  servers.first
end

#remote_rootObject



42
43
44
# File 'lib/geordi/capistrano_config.rb', line 42

def remote_root
  File.join deploy_info[/^\s*set\s*:deploy_to,\s*['"](.*?)['"]/, 1], 'current'
end

#serversObject



17
18
19
# File 'lib/geordi/capistrano_config.rb', line 17

def servers
  deploy_info.scan(/^\s*server\s*['"](.*?)['"]/).flatten
end

#shellObject



50
51
52
# File 'lib/geordi/capistrano_config.rb', line 50

def shell
  'bash --login'
end

#user(server) ⇒ Object



12
13
14
15
# File 'lib/geordi/capistrano_config.rb', line 12

def user(server)
  cap2user = deploy_info[/^\s*set\s*:user,\s*['"](.*?)['"]/, 1]
  cap2user || deploy_info[/^\s*server\s*['"]#{server}['"],.*user.{1,4}['"](.*?)['"]/, 1]
end