Class: Net::SSH::HostKeys

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/net/ssh/known_hosts.rb

Overview

Represents the result of a search in known hosts see search_for

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host_keys, host, known_hosts, options = {}) ⇒ HostKeys

Returns a new instance of HostKeys.



104
105
106
107
108
109
# File 'lib/net/ssh/known_hosts.rb', line 104

def initialize(host_keys, host, known_hosts, options = {})
  @host_keys = host_keys
  @host = host
  @known_hosts = known_hosts
  @options = options
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



102
103
104
# File 'lib/net/ssh/known_hosts.rb', line 102

def host
  @host
end

Instance Method Details

#add_host_key(key) ⇒ Object



111
112
113
114
# File 'lib/net/ssh/known_hosts.rb', line 111

def add_host_key(key)
  @known_hosts.add(@host, key, @options)
  @host_keys.push(key)
end

#each(&block) ⇒ Object



116
117
118
# File 'lib/net/ssh/known_hosts.rb', line 116

def each(&block)
  @host_keys.each(&block)
end

#empty?Boolean

Returns:

  • (Boolean)


120
121
122
# File 'lib/net/ssh/known_hosts.rb', line 120

def empty?
  @host_keys.empty?
end

#hostnameObject

Returns the bare hostname, stripping port and IP portions from the comma-separated host string used internally.

Examples:

"server.example.com"            => "server.example.com"
"server.example.com,1.2.3.4"    => "server.example.com"
"[server.example.com]:2222"      => "server.example.com"


131
132
133
# File 'lib/net/ssh/known_hosts.rb', line 131

def hostname
  @host.split(",").first.gsub(/\[|\]:\d+/, "")
end