Class: Minestrone::Deploy::RemoteDependency

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ RemoteDependency

Returns a new instance of RemoteDependency.



11
12
13
14
15
# File 'lib/minestrone/recipes/deploy/remote_dependency.rb', line 11

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

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



8
9
10
# File 'lib/minestrone/recipes/deploy/remote_dependency.rb', line 8

def configuration
  @configuration
end

#hostsObject (readonly)

Returns the value of attribute hosts.



9
10
11
# File 'lib/minestrone/recipes/deploy/remote_dependency.rb', line 9

def hosts
  @hosts
end

Instance Method Details

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



35
36
37
38
39
# File 'lib/minestrone/recipes/deploy/remote_dependency.rb', line 35

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

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



48
49
50
51
52
# File 'lib/minestrone/recipes/deploy/remote_dependency.rb', line 48

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



17
18
19
20
21
# File 'lib/minestrone/recipes/deploy/remote_dependency.rb', line 17

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

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



23
24
25
26
27
# File 'lib/minestrone/recipes/deploy/remote_dependency.rb', line 23

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

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



41
42
43
44
45
46
# File 'lib/minestrone/recipes/deploy/remote_dependency.rb', line 41

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



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/minestrone/recipes/deploy/remote_dependency.rb', line 60

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



99
100
101
102
103
# File 'lib/minestrone/recipes/deploy/remote_dependency.rb', line 99

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

#or(message) ⇒ Object



90
91
92
93
# File 'lib/minestrone/recipes/deploy/remote_dependency.rb', line 90

def or(message)
  @message = message
  self
end

#pass?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/minestrone/recipes/deploy/remote_dependency.rb', line 95

def pass?
  @success
end

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



54
55
56
57
58
# File 'lib/minestrone/recipes/deploy/remote_dependency.rb', line 54

def rpm(name, version, options = {})
  @message ||= "package `#{name}' #{version} could not be found"
  try("rpm -q #{name} | grep '#{version}'", options)
  self
end

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



29
30
31
32
33
# File 'lib/minestrone/recipes/deploy/remote_dependency.rb', line 29

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