Class: Sunzi::Endpoint

Inherits:
Object show all
Defined in:
lib/sunzi/endpoint.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ Endpoint

Returns a new instance of Endpoint.



7
8
9
10
11
12
13
14
15
# File 'lib/sunzi/endpoint.rb', line 7

def initialize(input)
  input.match(/(.*@)?(.*?)(:.*)?$/)
  # Load ssh config if it exists
  ssh = Net::SSH::Config.for($2)

  @user = $1 && $1.delete('@') || ssh[:user] || 'root'
  @host = ssh[:host_name] || $2
  @port = $3 && $3.delete(':') || ssh[:port] && ssh[:port].to_s || '22'
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



5
6
7
# File 'lib/sunzi/endpoint.rb', line 5

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



5
6
7
# File 'lib/sunzi/endpoint.rb', line 5

def port
  @port
end

#userObject (readonly)

Returns the value of attribute user.



5
6
7
# File 'lib/sunzi/endpoint.rb', line 5

def user
  @user
end