Class: SSHKit::Host
- Inherits:
-
Object
- Object
- SSHKit::Host
- Defined in:
- lib/sshkit/host.rb
Instance Attribute Summary collapse
-
#hostname ⇒ Object
Returns the value of attribute hostname.
-
#password ⇒ Object
Returns the value of attribute password.
-
#port ⇒ Object
Returns the value of attribute port.
-
#ssh_options ⇒ Object
Returns the value of attribute ssh_options.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #eql?(other_host) ⇒ Boolean (also: #==, #equal?)
- #hash ⇒ Object
-
#initialize(host_string_or_options_hash) ⇒ Host
constructor
A new instance of Host.
- #key=(new_key) ⇒ Object
- #keys ⇒ Object
- #keys=(new_keys) ⇒ Object
- #netssh_options ⇒ Object
- #properties ⇒ Object
- #to_s ⇒ Object
- #username ⇒ Object
Constructor Details
#initialize(host_string_or_options_hash) ⇒ Host
Returns a new instance of Host.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/sshkit/host.rb', line 23 def initialize() unless .is_a?(Hash) suitable_parsers = [ SimpleHostParser, HostWithPortParser, HostWithUsernameAndPortParser, IPv6HostWithPortParser, HostWithUsernameParser, HostWithUsernameAndPortParser ].select do |p| p.suitable?() end if suitable_parsers.any? suitable_parsers.first.tap do |parser| @user, @hostname, @port = parser.new().attributes end else raise UnparsableHostStringError, "Cannot parse host string #{}" end else .each do |key, value| if self.respond_to?("#{key}=") send("#{key}=", value) else raise ArgumentError, "Unknown host property #{key}" end end end end |
Instance Attribute Details
#hostname ⇒ Object
Returns the value of attribute hostname.
9 10 11 |
# File 'lib/sshkit/host.rb', line 9 def hostname @hostname end |
#password ⇒ Object
Returns the value of attribute password.
9 10 11 |
# File 'lib/sshkit/host.rb', line 9 def password @password end |
#port ⇒ Object
Returns the value of attribute port.
9 10 11 |
# File 'lib/sshkit/host.rb', line 9 def port @port end |
#ssh_options ⇒ Object
Returns the value of attribute ssh_options.
9 10 11 |
# File 'lib/sshkit/host.rb', line 9 def @ssh_options end |
#user ⇒ Object
Returns the value of attribute user.
9 10 11 |
# File 'lib/sshkit/host.rb', line 9 def user @user end |
Instance Method Details
#eql?(other_host) ⇒ Boolean Also known as: ==, equal?
63 64 65 |
# File 'lib/sshkit/host.rb', line 63 def eql?(other_host) other_host.hash == hash end |
#hash ⇒ Object
55 56 57 |
# File 'lib/sshkit/host.rb', line 55 def hash user.hash ^ hostname.hash ^ port.hash end |
#key=(new_key) ⇒ Object
11 12 13 |
# File 'lib/sshkit/host.rb', line 11 def key=(new_key) @keys = [new_key] end |
#keys ⇒ Object
19 20 21 |
# File 'lib/sshkit/host.rb', line 19 def keys Array(@keys) end |
#keys=(new_keys) ⇒ Object
15 16 17 |
# File 'lib/sshkit/host.rb', line 15 def keys=(new_keys) @keys = new_keys end |
#netssh_options ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/sshkit/host.rb', line 73 def {}.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( || {}) end |
#properties ⇒ Object
84 85 86 |
# File 'lib/sshkit/host.rb', line 84 def properties @properties ||= OpenStruct.new end |
#to_s ⇒ Object
69 70 71 |
# File 'lib/sshkit/host.rb', line 69 def to_s hostname end |
#username ⇒ Object
59 60 61 |
# File 'lib/sshkit/host.rb', line 59 def username user end |