Module: Shuttle::Helpers

Included in:
Deploy
Defined in:
lib/shuttle/helpers.rb

Constant Summary collapse

LEVEL_COLORS =
{
  'info'    => :green,
  'warning' => :yellow,
  'error'   => :red
}

Instance Method Summary collapse

Instance Method Details

#deployer_hostnameObject



52
53
54
# File 'lib/shuttle/helpers.rb', line 52

def deployer_hostname
  `hostname`.strip
end

#error(message) ⇒ Object

Raises:



14
15
16
17
18
19
# File 'lib/shuttle/helpers.rb', line 14

def error(message)
  log("ERROR: #{message}", "error")
  log("Release v#{version} aborted", "error")
  
  raise DeployError, message
end

#git_installed?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/shuttle/helpers.rb', line 25

def git_installed?
  ssh.run("which git").success?
end

#git_remoteObject



42
43
44
45
46
47
48
49
50
# File 'lib/shuttle/helpers.rb', line 42

def git_remote
  result = ssh.run("cd #{scm_path} && git remote -v")

  if result.success?
    result.output.scan(/^origin\t(.+)\s\(fetch\)/).flatten.first
  else
    nil
  end
end

#log(message, level = 'info') ⇒ Object



9
10
11
12
# File 'lib/shuttle/helpers.rb', line 9

def log(message, level='info')
  prefix = "----->".send(LEVEL_COLORS[level])
  STDOUT.puts("#{prefix} #{message}")
end

#release_exists?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/shuttle/helpers.rb', line 33

def release_exists?
  ssh.directory_exists?(release_path)
end

#stream_output(buff) ⇒ Object



37
38
39
40
# File 'lib/shuttle/helpers.rb', line 37

def stream_output(buff)
  str = buff.split("\n").map { |str| "       #{str}"}.join("\n")
  STDOUT.puts(str)
end

#svn_installed?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/shuttle/helpers.rb', line 29

def svn_installed?
  ssh.run("which svn").success?
end

#warn(message) ⇒ Object



21
22
23
# File 'lib/shuttle/helpers.rb', line 21

def warn(message)
  log("WARNING: #{message}", "warning")
end