Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

root/tools/capistrano/lib/capistrano/server_definition.rb

Revision 6706, 1.2 kB (checked in by minam, 2 years ago)

Make the server definition itself available to SSH channels, rather that just the host name. Identify servers by their complete credentials in logs, rather than simply by hostname.

Line 
1 module Capistrano
2   class ServerDefinition
3     include Comparable
4
5     attr_reader :host
6     attr_reader :user
7     attr_reader :port
8     attr_reader :options
9
10     def initialize(string, options={})
11       @user, @host, @port = string.match(/^(?:([^;,:=]+)@|)(.*?)(?::(\d+)|)$/)[1,3]
12
13       @options = options.dup
14       user_opt, port_opt = @options.delete(:user), @options.delete(:port)
15
16       @user ||= user_opt
17       @port ||= port_opt
18
19       @port = @port.to_i if @port
20     end
21
22     def <=>(server)
23       [host, port, user] <=> [server.host, server.port, server.user]
24     end
25
26     # Redefined, so that Array#uniq will work to remove duplicate server
27     # definitions, based solely on their host names.
28     def eql?(server)
29       host == server.host &&
30         user == server.user &&
31         port == server.port
32     end
33
34     alias :== :eql?
35
36     # Redefined, so that Array#uniq will work to remove duplicate server
37     # definitions, based on their connection information.
38     def hash
39       @hash ||= [host, user, port].hash
40     end
41
42     def to_s
43       @to_s ||= begin
44         s = host
45         s = "#{user}@#{s}" if user
46         s = "#{s}:#{port}" if port && port != 22
47         s
48       end
49     end
50   end
51 end
Note: See TracBrowser for help on using the browser.