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.
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.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/capistrano/server_definition.rb', line 10 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 |
Instance Method Details
#<=>(server) ⇒ Object
22 23 24 |
# File 'lib/capistrano/server_definition.rb', line 22 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.
28 29 30 31 32 |
# File 'lib/capistrano/server_definition.rb', line 28 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.
38 39 40 |
# File 'lib/capistrano/server_definition.rb', line 38 def hash @hash ||= [host, user, port].hash end |
#to_s ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/capistrano/server_definition.rb', line 42 def to_s @to_s ||= begin s = host s = "#{user}@#{s}" if user s = "#{s}:#{port}" if port && port != 22 s end end |