Class: RunSSHLib::SshHostDef

Inherits:
Object
  • Object
show all
Defined in:
lib/runsshlib/ssh_host_def.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(definition) ⇒ SshHostDef

Initialize ssh host def with definition.

definition

A hash containing ssh options. :host_name is required. Could also be a hostname (string) for quick defining SshHostDef with only hostname.

Raises:

  • (ArgumentError)


27
28
29
30
31
32
33
# File 'lib/runsshlib/ssh_host_def.rb', line 27

def initialize(definition)
  if definition.instance_of? String
    definition = { :host_name => definition }
  end
  raise ArgumentError, "Missing hostname" unless definition[:host_name]
  @definition = definition
end

Instance Attribute Details

#definitionObject (readonly)

Returns the value of attribute definition.



20
21
22
# File 'lib/runsshlib/ssh_host_def.rb', line 20

def definition
  @definition
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?

should be equal if @definition is equal



36
37
38
39
40
# File 'lib/runsshlib/ssh_host_def.rb', line 36

def ==(other)
  return false if other.nil?
  return false unless other.instance_of? SshHostDef
  definition == other.definition
end

#to_printObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/runsshlib/ssh_host_def.rb', line 43

def to_print
  out =    "    * host: #{definition[:host_name]}"
  out << "\n    * login: #{definition[:login] || 'current user'}"
  if definition[:local_tunnel]
    tunnel = RunSSHLib::SshBackend.normalize_tunnel_definition(definition[:local_tunnel])
    out << "\n    * local tunnel: #{tunnel}"
  end
  if definition[:option] && definition[:option].any?
    out << "\n    * ssh options:"
    definition[:option].each do |option|
      out << "\n      - #{option}"
    end
  end
  out
end