jamis / capistrano

Remote multi-server automation tool. This repository is no longer being actively maintained. Please ask on the mailing list to find someone who has a well-maintained fork. Thanks!

This URL has Read+Write access

capistrano / lib / capistrano / server_definition.rb
100644 56 lines (45 sloc) 1.38 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
module Capistrano
  class ServerDefinition
    include Comparable
 
    attr_reader :host
    attr_reader :user
    attr_reader :port
    attr_reader :options
 
    # The default user name to use when a user name is not explicitly provided
    def self.default_user
      ENV['USER'] || ENV['USERNAME'] || "not-specified"
    end
 
    def initialize(string, options={})
      @user, @host, @port = string.match(/^(?:([^;,:=]+)@|)(.*?)(?::(\d+)|)$/)[1,3]
 
      @options = options.dup
      user_opt, port_opt = @options.delete(:user), @options.delete(:port)
 
      @user ||= user_opt
      @port ||= port_opt
 
      @port = @port.to_i if @port
    end
 
    def <=>(server)
      [host, port, user] <=> [server.host, server.port, server.user]
    end
 
    # Redefined, so that Array#uniq will work to remove duplicate server
    # definitions, based solely on their host names.
    def eql?(server)
      host == server.host &&
        user == server.user &&
        port == server.port
    end
 
    alias :== :eql?
 
    # Redefined, so that Array#uniq will work to remove duplicate server
    # definitions, based on their connection information.
    def hash
      @hash ||= [host, user, port].hash
    end
 
    def to_s
      @to_s ||= begin
        s = host
        s = "#{user}@#{s}" if user
        s = "#{s}:#{port}" if port && port != 22
        s
      end
    end
  end
end