Class: SSHKit::Host

Inherits:
Object
  • Object
show all
Defined in:
lib/sshkit/host.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host_string) ⇒ Host

Returns a new instance of Host.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/sshkit/host.rb', line 13

def initialize(host_string)

  suitable_parsers = [
    SimpleHostParser,
    HostWithPortParser,
    IPv6HostWithPortParser,
    HostWithUsernameParser,
    HostWithUsernameAndPortParser
  ].select do |p|
    p.suitable?(host_string)
  end

  if suitable_parsers.any?
    suitable_parsers.first.tap do |parser|
      @username, @hostname, @port = parser.new(host_string).attributes
    end
  else
    raise UnparsableHostStringError, "Cannot parse host string #{host_string}"
  end

end

Instance Attribute Details

#hostnameObject (readonly)

Returns the value of attribute hostname.



9
10
11
# File 'lib/sshkit/host.rb', line 9

def hostname
  @hostname
end

#passwordObject

Returns the value of attribute password.



11
12
13
# File 'lib/sshkit/host.rb', line 11

def password
  @password
end

#portObject (readonly)

Returns the value of attribute port.



9
10
11
# File 'lib/sshkit/host.rb', line 9

def port
  @port
end

#usernameObject (readonly)

Returns the value of attribute username.



9
10
11
# File 'lib/sshkit/host.rb', line 9

def username
  @username
end

Instance Method Details

#eql?(other_host) ⇒ Boolean Also known as: ==, equal?

Returns:

  • (Boolean)


39
40
41
# File 'lib/sshkit/host.rb', line 39

def eql?(other_host)
  other_host.hash == hash
end

#hashObject



35
36
37
# File 'lib/sshkit/host.rb', line 35

def hash
  username.hash ^ hostname.hash ^ port.hash
end

#propertiesObject



53
54
55
# File 'lib/sshkit/host.rb', line 53

def properties
  @properties ||= OpenStruct.new
end

#to_keyObject



45
46
47
# File 'lib/sshkit/host.rb', line 45

def to_key
  to_s.to_sym
end

#to_sObject



49
50
51
# File 'lib/sshkit/host.rb', line 49

def to_s
  sprintf("%s@%s:%d", username, hostname, port)
end