Class: Capistrano::Deploy::RemoteDependency
- Inherits:
-
Object
- Object
- Capistrano::Deploy::RemoteDependency
- Defined in:
- lib/capistrano/recipes/deploy/remote_dependency.rb
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#hosts ⇒ Object
readonly
Returns the value of attribute hosts.
Instance Method Summary collapse
- #command(command, options = {}) ⇒ Object
- #deb(name, version, options = {}) ⇒ Object
- #directory(path, options = {}) ⇒ Object
- #file(path, options = {}) ⇒ Object
- #gem(name, version, options = {}) ⇒ Object
-
#initialize(configuration) ⇒ RemoteDependency
constructor
A new instance of RemoteDependency.
- #match(command, expect, options = {}) ⇒ Object
- #message ⇒ Object
- #or(message) ⇒ Object
- #pass? ⇒ Boolean
- #rpm(name, version, options = {}) ⇒ Object
- #writable(path, options = {}) ⇒ Object
Constructor Details
#initialize(configuration) ⇒ RemoteDependency
Returns a new instance of RemoteDependency.
9 10 11 12 13 |
# File 'lib/capistrano/recipes/deploy/remote_dependency.rb', line 9 def initialize(configuration) @configuration = configuration @success = true @hosts = nil end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
6 7 8 |
# File 'lib/capistrano/recipes/deploy/remote_dependency.rb', line 6 def configuration @configuration end |
#hosts ⇒ Object (readonly)
Returns the value of attribute hosts.
7 8 9 |
# File 'lib/capistrano/recipes/deploy/remote_dependency.rb', line 7 def hosts @hosts end |
Instance Method Details
#command(command, options = {}) ⇒ Object
33 34 35 36 37 |
# File 'lib/capistrano/recipes/deploy/remote_dependency.rb', line 33 def command(command, ={}) @message ||= "`#{command}' could not be found in the path" try("which #{command}", ) self end |
#deb(name, version, options = {}) ⇒ Object
46 47 48 49 50 |
# File 'lib/capistrano/recipes/deploy/remote_dependency.rb', line 46 def deb(name, version, ={}) @message ||= "package `#{name}' #{version} could not be found" try("dpkg -s #{name} | grep '^Version: #{version}'", ) self end |
#directory(path, options = {}) ⇒ Object
15 16 17 18 19 |
# File 'lib/capistrano/recipes/deploy/remote_dependency.rb', line 15 def directory(path, ={}) @message ||= "`#{path}' is not a directory" try("test -d #{path}", ) self end |
#file(path, options = {}) ⇒ Object
21 22 23 24 25 |
# File 'lib/capistrano/recipes/deploy/remote_dependency.rb', line 21 def file(path, ={}) @message ||= "`#{path}' is not a file" try("test -f #{path}", ) self end |
#gem(name, version, options = {}) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/capistrano/recipes/deploy/remote_dependency.rb', line 39 def gem(name, version, ={}) @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 }'", ) self end |
#match(command, expect, options = {}) ⇒ Object
58 59 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 |
# File 'lib/capistrano/recipes/deploy/remote_dependency.rb', line 58 def match(command, expect, ={}) expect = Regexp.new(Regexp.escape(expect.to_s)) unless expect.is_a?(Regexp) output_per_server = {} try("#{command} ", ) 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 |
#message ⇒ Object
97 98 99 100 101 |
# File 'lib/capistrano/recipes/deploy/remote_dependency.rb', line 97 def s = @message.dup s << " (#{@hosts})" if @hosts s end |
#or(message) ⇒ Object
88 89 90 91 |
# File 'lib/capistrano/recipes/deploy/remote_dependency.rb', line 88 def or() @message = self end |
#pass? ⇒ Boolean
93 94 95 |
# File 'lib/capistrano/recipes/deploy/remote_dependency.rb', line 93 def pass? @success end |
#rpm(name, version, options = {}) ⇒ Object
52 53 54 55 56 |
# File 'lib/capistrano/recipes/deploy/remote_dependency.rb', line 52 def rpm(name, version, ={}) @message ||= "package `#{name}' #{version} could not be found" try("rpm -q #{name} | grep '#{version}'", ) self end |
#writable(path, options = {}) ⇒ Object
27 28 29 30 31 |
# File 'lib/capistrano/recipes/deploy/remote_dependency.rb', line 27 def writable(path, ={}) @message ||= "`#{path}' is not writable" try("test -w #{path}", ) self end |