class SSHKit::Host
Attributes
hostname[RW]
password[RW]
port[RW]
ssh_options[RW]
user[RW]
Public Class Methods
new(host_string_or_options_hash)
click to toggle source
# File lib/sshkit/host.rb, line 23 def initialize(host_string_or_options_hash) @keys = [] @local = false if host_string_or_options_hash == :local @local = true @hostname = "localhost" @user = ENV['USER'] || ENV['LOGNAME'] || ENV['USERNAME'] elsif !host_string_or_options_hash.is_a?(Hash) @user, @hostname, @port = first_suitable_parser(host_string_or_options_hash).attributes else host_string_or_options_hash.each do |key, value| if self.respond_to?("#{key}=") send("#{key}=", value) else raise ArgumentError, "Unknown host property #{key}" end end end end
Public Instance Methods
eql?(other_host)
click to toggle source
# File lib/sshkit/host.rb, line 56 def eql?(other_host) other_host.hash == hash end
first_suitable_parser(host)
click to toggle source
# File lib/sshkit/host.rb, line 81 def first_suitable_parser(host) parser = PARSERS.find{|p| p.suitable?(host) } fail UnparsableHostStringError, "Cannot parse host string #{host}" if parser.nil? parser.new(host) end
hash()
click to toggle source
# File lib/sshkit/host.rb, line 48 def hash user.hash ^ hostname.hash ^ port.hash end
key=(new_key)
click to toggle source
# File lib/sshkit/host.rb, line 11 def key=(new_key) @keys = [new_key] end
keys()
click to toggle source
# File lib/sshkit/host.rb, line 19 def keys Array(@keys) end
keys=(new_keys)
click to toggle source
# File lib/sshkit/host.rb, line 15 def keys=(new_keys) @keys = new_keys end
local?()
click to toggle source
# File lib/sshkit/host.rb, line 44 def local? @local end
netssh_options()
click to toggle source
# File lib/sshkit/host.rb, line 66 def netssh_options {}.tap do |sho| sho[:keys] = keys if keys.any? sho[:port] = port if port sho[:user] = user if user sho[:password] = password if password sho[:forward_agent] = true end .merge(ssh_options || {}) end
properties()
click to toggle source
# File lib/sshkit/host.rb, line 77 def properties @properties ||= OpenStruct.new end
to_s()
click to toggle source
# File lib/sshkit/host.rb, line 62 def to_s hostname end
username()
click to toggle source
# File lib/sshkit/host.rb, line 52 def username user end