Class: Capistrano::ServerDefinition

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/capistrano/server_definition.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string, options = {}) ⇒ ServerDefinition

Returns a new instance of ServerDefinition.


15
16
17
18
19
20
21
22
23
24
25
# File 'lib/capistrano/server_definition.rb', line 15

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

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host


5
6
7
# File 'lib/capistrano/server_definition.rb', line 5

def host
  @host
end

#optionsObject (readonly)

Returns the value of attribute options


8
9
10
# File 'lib/capistrano/server_definition.rb', line 8

def options
  @options
end

#portObject (readonly)

Returns the value of attribute port


7
8
9
# File 'lib/capistrano/server_definition.rb', line 7

def port
  @port
end

#userObject (readonly)

Returns the value of attribute user


6
7
8
# File 'lib/capistrano/server_definition.rb', line 6

def user
  @user
end

Class Method Details

.default_userObject

The default user name to use when a user name is not explicitly provided


11
12
13
# File 'lib/capistrano/server_definition.rb', line 11

def self.default_user
  ENV['USER'] || ENV['USERNAME'] || "not-specified"
end

Instance Method Details

#<=>(server) ⇒ Object


27
28
29
# File 'lib/capistrano/server_definition.rb', line 27

def <=>(server)
  [host, port, user] <=> [server.host, server.port, server.user]
end

#eql?(server) ⇒ Boolean Also known as: ==

Redefined, so that Array#uniq will work to remove duplicate server definitions, based solely on their host names.

Returns:

  • (Boolean)

33
34
35
36
37
# File 'lib/capistrano/server_definition.rb', line 33

def eql?(server)
  host == server.host &&
    user == server.user &&
    port == server.port
end

#hashObject

Redefined, so that Array#uniq will work to remove duplicate server definitions, based on their connection information.


43
44
45
# File 'lib/capistrano/server_definition.rb', line 43

def hash
  @hash ||= [host, user, port].hash
end

#to_sObject


47
48
49
50
51
52
53
54
# File 'lib/capistrano/server_definition.rb', line 47

def to_s
  @to_s ||= begin
    s = host
    s = "#{user}@#{s}" if user
    s = "#{s}:#{port}" if port && port != 22
    s
  end
end