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
- #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
- #writable(path, options = {}) ⇒ Object
Constructor Details
#initialize(configuration) ⇒ RemoteDependency
Returns a new instance of RemoteDependency.
9 10 11 12 |
# File 'lib/capistrano/recipes/deploy/remote_dependency.rb', line 9 def initialize(configuration) @configuration = configuration @success = true 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
32 33 34 35 36 |
# File 'lib/capistrano/recipes/deploy/remote_dependency.rb', line 32 def command(command, ={}) @message ||= "`#{command}' could not be found in the path" try("which #{command}", ) self end |
#directory(path, options = {}) ⇒ Object
14 15 16 17 18 |
# File 'lib/capistrano/recipes/deploy/remote_dependency.rb', line 14 def directory(path, ={}) @message ||= "`#{path}' is not a directory" try("test -d #{path}", ) self end |
#file(path, options = {}) ⇒ Object
20 21 22 23 24 |
# File 'lib/capistrano/recipes/deploy/remote_dependency.rb', line 20 def file(path, ={}) @message ||= "`#{path}' is not a file" try("test -f #{path}", ) self end |
#gem(name, version, options = {}) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/capistrano/recipes/deploy/remote_dependency.rb', line 38 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
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/capistrano/recipes/deploy/remote_dependency.rb', line 45 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
84 85 86 87 88 |
# File 'lib/capistrano/recipes/deploy/remote_dependency.rb', line 84 def s = @message.dup s << " (#{@hosts})" if @hosts && @hosts.any? s end |
#or(message) ⇒ Object
75 76 77 78 |
# File 'lib/capistrano/recipes/deploy/remote_dependency.rb', line 75 def or() @message = self end |
#pass? ⇒ Boolean
80 81 82 |
# File 'lib/capistrano/recipes/deploy/remote_dependency.rb', line 80 def pass? @success end |
#writable(path, options = {}) ⇒ Object
26 27 28 29 30 |
# File 'lib/capistrano/recipes/deploy/remote_dependency.rb', line 26 def writable(path, ={}) @message ||= "`#{path}' is not writable" try("test -w #{path}", ) self end |