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.
-
#transfer_method ⇒ Object
Returns the value of attribute transfer_method.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #eql?(other_host) ⇒ Boolean (also: #==, #equal?)
- #first_suitable_parser(host) ⇒ Object
- #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
- #local? ⇒ Boolean
- #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.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/sshkit/host.rb', line 25 def initialize() @keys = [] @local = false if == :local @local = true @hostname = "localhost" @user = ENV['USER'] || ENV['LOGNAME'] || ENV['USERNAME'] elsif !.is_a?(Hash) @user, @hostname, @port = first_suitable_parser().attributes 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.
10 11 12 |
# File 'lib/sshkit/host.rb', line 10 def hostname @hostname end |
#password ⇒ Object
Returns the value of attribute password.
10 11 12 |
# File 'lib/sshkit/host.rb', line 10 def password @password end |
#port ⇒ Object
Returns the value of attribute port.
10 11 12 |
# File 'lib/sshkit/host.rb', line 10 def port @port end |
#ssh_options ⇒ Object
Returns the value of attribute ssh_options.
10 11 12 |
# File 'lib/sshkit/host.rb', line 10 def @ssh_options end |
#transfer_method ⇒ Object
Returns the value of attribute transfer_method.
11 12 13 |
# File 'lib/sshkit/host.rb', line 11 def transfer_method @transfer_method end |
#user ⇒ Object
Returns the value of attribute user.
10 11 12 |
# File 'lib/sshkit/host.rb', line 10 def user @user end |
Instance Method Details
#eql?(other_host) ⇒ Boolean Also known as: ==, equal?
64 65 66 |
# File 'lib/sshkit/host.rb', line 64 def eql?(other_host) other_host.hash == hash end |
#first_suitable_parser(host) ⇒ Object
89 90 91 92 93 |
# File 'lib/sshkit/host.rb', line 89 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 ⇒ Object
56 57 58 |
# File 'lib/sshkit/host.rb', line 56 def hash user.hash ^ hostname.hash ^ port.hash end |
#key=(new_key) ⇒ Object
13 14 15 |
# File 'lib/sshkit/host.rb', line 13 def key=(new_key) @keys = [new_key] end |
#keys ⇒ Object
21 22 23 |
# File 'lib/sshkit/host.rb', line 21 def keys Array(@keys) end |
#keys=(new_keys) ⇒ Object
17 18 19 |
# File 'lib/sshkit/host.rb', line 17 def keys=(new_keys) @keys = new_keys end |
#local? ⇒ Boolean
52 53 54 |
# File 'lib/sshkit/host.rb', line 52 def local? @local end |
#netssh_options ⇒ Object
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/sshkit/host.rb', line 74 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
85 86 87 |
# File 'lib/sshkit/host.rb', line 85 def properties @properties ||= OpenStruct.new end |
#to_s ⇒ Object
70 71 72 |
# File 'lib/sshkit/host.rb', line 70 def to_s hostname end |
#username ⇒ Object
60 61 62 |
# File 'lib/sshkit/host.rb', line 60 def username user end |