Class: SSHKit::Host

### Home Classes Methods

### In Files

- lib/sshkit/host.rb

### Parent

Object

### Methods

- ::new
- #==
- #eql?
- #equal?
- #hash
- #key=
- #keys
- #keys=
- #local?
- #netssh_options
- #properties
- #to_s
- #username

### Class/Module Index

Quicksearch

- SSHKit
- SSHKit::Backend
- SSHKit::Backend::Abstract
- SSHKit::Backend::ConnectionPool
- SSHKit::Backend::Local
- SSHKit::Backend::Netssh
- SSHKit::Backend::Netssh::Configuration
- SSHKit::Backend::Printer
- SSHKit::Backend::Skipper
- SSHKit::CommandMap
- SSHKit::CommandMap::CommandHash
- SSHKit::CommandMap::PrefixProvider
- SSHKit::Configuration
- SSHKit::Coordinator
- SSHKit::DSL
- SSHKit::Formatter
- SSHKit::Formatter::Abstract
- SSHKit::Formatter::BlackHole
- SSHKit::Formatter::Dot
- SSHKit::Formatter::Pretty
- SSHKit::Formatter::SimpleText
- SSHKit::Host
- SSHKit::HostWithPortParser
- SSHKit::HostWithUsernameAndPortParser
- SSHKit::HostWithUsernameParser
- SSHKit::IPv6HostWithPortParser
- SSHKit::LogMessage
- SSHKit::Logger
- SSHKit::Logger::SSHKit
- SSHKit::Logger::SSHKit::Logger
- SSHKit::Logger::SSHKit::Logger::Net
- SSHKit::Logger::SSHKit::Logger::Net::SSH
- SSHKit::Logger::SSHKit::Logger::Net::SSH::LogLevelShim
- SSHKit::Runner
- SSHKit::Runner::Abstract
- SSHKit::Runner::ExecuteError
- SSHKit::Runner::Group
- SSHKit::Runner::Null
- SSHKit::Runner::Parallel
- SSHKit::Runner::Sequential
- SSHKit::SimpleHostParser
- SSHKit::Utils
- SSHKit::Utils::CaptureOutputMethods
- Net
- Net::SSH
- Net::SSH::Config
- Array
- Color
- Hash
- Object

No matching classes.

# 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 24
    def initialize(host_string_or_options_hash)

      if host_string_or_options_hash == :local
        @local = true
        @hostname = "localhost"
        @user = Etc.getpwuid.name
      elsif !host_string_or_options_hash.is_a?(Hash)
        suitable_parsers = [
          SimpleHostParser,
          HostWithPortParser,
          HostWithUsernameAndPortParser,
          IPv6HostWithPortParser,
          HostWithUsernameParser,
        ].select do |p|
          p.suitable?(host_string_or_options_hash)
        end

        if suitable_parsers.any?
          suitable_parsers.first.tap do |parser|
            @user, @hostname, @port = parser.new(host_string_or_options_hash).attributes
          end
        else
          raise UnparsableHostStringError, "Cannot parse host string #{host_string_or_options_hash}"
        end
      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

==(other_host) click to toggle source
Alias for: eql?
eql?(other_host) click to toggle source

    # File lib/sshkit/host.rb, line 71
    def eql?(other_host)
      other_host.hash == hash
    end

Also aliased as: ==, equal?
equal?(other_host) click to toggle source
Alias for: eql?
hash() click to toggle source

    # File lib/sshkit/host.rb, line 63
    def hash
      user.hash ^ hostname.hash ^ port.hash
    end

key=(new_key) click to toggle source

    # File lib/sshkit/host.rb, line 12
    def key=(new_key)
      @keys = [new_key]
    end

keys() click to toggle source

    # File lib/sshkit/host.rb, line 20
    def keys
      Array(@keys)
    end

keys=(new_keys) click to toggle source

    # File lib/sshkit/host.rb, line 16
    def keys=(new_keys)
      @keys = new_keys
    end

local?() click to toggle source

    # File lib/sshkit/host.rb, line 59
    def local?
      @local
    end

netssh_options() click to toggle source

    # File lib/sshkit/host.rb, line 81
    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 92
    def properties
      @properties ||= OpenStruct.new
    end

to_s() click to toggle source

    # File lib/sshkit/host.rb, line 77
    def to_s
      hostname
    end

username() click to toggle source

    # File lib/sshkit/host.rb, line 67
    def username
      user
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.