Class: Capistrano::Deploy::RemoteDependency

Inherits:
Object
  • Object
show all
Defined in:
lib/alpha_omega/deploy/remote_dependency.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ RemoteDependency

Returns a new instance of RemoteDependency.



9
10
11
12
13
# File 'lib/alpha_omega/deploy/remote_dependency.rb', line 9

def initialize(configuration)
  @configuration = configuration
  @success = true
  @hosts = nil
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



6
7
8
# File 'lib/alpha_omega/deploy/remote_dependency.rb', line 6

def configuration
  @configuration
end

#hostsObject (readonly)

Returns the value of attribute hosts.



7
8
9
# File 'lib/alpha_omega/deploy/remote_dependency.rb', line 7

def hosts
  @hosts
end

Instance Method Details

#command(command, options = {}) ⇒ Object



33
34
35
36
37
# File 'lib/alpha_omega/deploy/remote_dependency.rb', line 33

def command(command, options={})
  @message ||= "`#{command}' could not be found in the path"
  try("which #{command}", options)
  self
end

#deb(name, version, options = {}) ⇒ Object



46
47
48
49
50
# File 'lib/alpha_omega/deploy/remote_dependency.rb', line 46

def deb(name, version, options={})
  @message ||= "package `#{name}' #{version} could not be found"
  try("dpkg -s #{name} | grep '^Version: #{version}'", options)
  self
end

#directory(path, options = {}) ⇒ Object



15
16
17
18
19
# File 'lib/alpha_omega/deploy/remote_dependency.rb', line 15

def directory(path, options={})
  @message ||= "`#{path}' is not a directory"
  try("test -d #{path}", options)
  self
end

#file(path, options = {}) ⇒ Object



21
22
23
24
25
# File 'lib/alpha_omega/deploy/remote_dependency.rb', line 21

def file(path, options={})
  @message ||= "`#{path}' is not a file"
  try("test -f #{path}", options)
  self
end

#gem(name, version, options = {}) ⇒ Object



39
40
41
42
43
44
# File 'lib/alpha_omega/deploy/remote_dependency.rb', line 39

def gem(name, version, options={})
  @message ||= "gem `#{name}' #{version} could not be found"
  gem_cmd = configuration.fetch(:gem_command, "gem")
  try("#{gem_cmd} specification --version '#{version}' #{name} 2>&1 | awk 'BEGIN { s = 0 } /^name:/ { s = 1; exit }; END { if(s == 0) exit 1 }'", options)
  self
end

#match(command, expect, options = {}) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/alpha_omega/deploy/remote_dependency.rb', line 52

def match(command, expect, options={})
  expect = Regexp.new(Regexp.escape(expect.to_s)) unless expect.is_a?(Regexp)

  output_per_server = {} 
  try("#{command} ", options) do |ch, stream, out| 
    output_per_server[ch[:server]] ||= '' 
    output_per_server[ch[:server]] += out 
  end 

  # It is possible for some of these commands to return a status != 0
  # (for example, rake --version exits with a 1). For this check we
  # just care if the output matches, so we reset the success flag.
  @success = true

  errored_hosts = [] 
  output_per_server.each_pair do |server, output| 
    next if output =~ expect
    errored_hosts << server 
  end 

  if errored_hosts.any?
    @hosts = errored_hosts.join(', ')
    output = output_per_server[errored_hosts.first]
    @message = "the output #{output.inspect} from #{command.inspect} did not match #{expect.inspect}"
    @success = false
  end 

  self 
end

#messageObject



91
92
93
94
95
# File 'lib/alpha_omega/deploy/remote_dependency.rb', line 91

def message
  s = @message.dup
  s << " (#{@hosts})" if @hosts
  s
end

#or(message) ⇒ Object



82
83
84
85
# File 'lib/alpha_omega/deploy/remote_dependency.rb', line 82

def or(message)
  @message = message
  self
end

#pass?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/alpha_omega/deploy/remote_dependency.rb', line 87

def pass?
  @success
end

#writable(path, options = {}) ⇒ Object



27
28
29
30
31
# File 'lib/alpha_omega/deploy/remote_dependency.rb', line 27

def writable(path, options={})
  @message ||= "`#{path}' is not writable"
  try("test -w #{path}", options)
  self
end