Class: Capistrano::ServerDefinition
- Inherits:
-
Object
- Object
- Capistrano::ServerDefinition
- Includes:
- Comparable
- Defined in:
- lib/capistrano/server_definition.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Class Method Summary collapse
-
.default_user ⇒ Object
The default user name to use when a user name is not explicitly provided.
Instance Method Summary collapse
- #<=>(server) ⇒ Object
-
#eql?(server) ⇒ Boolean
(also: #==)
Redefined, so that Array#uniq will work to remove duplicate server definitions, based solely on their host names.
-
#hash ⇒ Object
Redefined, so that Array#uniq will work to remove duplicate server definitions, based on their connection information.
-
#initialize(string, options = {}) ⇒ ServerDefinition
constructor
A new instance of ServerDefinition.
- #to_s ⇒ Object
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, ={}) @user, @host, @port = string.match(/^(?:([^;,:=]+)@|)(.*?)(?::(\d+)|)$/)[1,3] @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
#host ⇒ Object (readonly)
Returns the value of attribute host.
5 6 7 |
# File 'lib/capistrano/server_definition.rb', line 5 def host @host end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/capistrano/server_definition.rb', line 8 def @options end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
7 8 9 |
# File 'lib/capistrano/server_definition.rb', line 7 def port @port end |
#user ⇒ Object (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_user ⇒ Object
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.
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 |
#hash ⇒ Object
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_s ⇒ Object
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 |