Class: Assh::Host

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

Constant Summary collapse

PORT_KEY =
"Port"
HOST_KEY =
Assh::FileProvider::HOST_KEY
HOSTNAME_KEY =
"HostName"
HOSTS_KEY =
Assh::FileProvider::HOSTS_KEY
GROUP_KEY =
Assh::FileProvider::GROUP_KEY
GROUPS_KEY =
Assh::FileProvider::GROUPS_KEY

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Host

Returns a new instance of Host.



17
18
19
20
21
22
23
# File 'lib/host.rb', line 17

def initialize(params)
	raise 'Unexpected params type' unless params.is_a? Hash
	@name = params.delete(HOST_KEY)
	@hostname = params.delete(HOSTNAME_KEY)
	@port = params.delete(PORT_KEY) || 22
	@params = params
end

Instance Attribute Details

#hostnameObject

Returns the value of attribute hostname.



15
16
17
# File 'lib/host.rb', line 15

def hostname
  @hostname
end

#nameObject

Returns the value of attribute name.



15
16
17
# File 'lib/host.rb', line 15

def name
  @name
end

#portObject

Returns the value of attribute port.



15
16
17
# File 'lib/host.rb', line 15

def port
  @port
end

Instance Method Details

#addressObject



25
26
27
# File 'lib/host.rb', line 25

def address
	"#{hostname}:#{port}"
end

#to_sObject



29
30
31
# File 'lib/host.rb', line 29

def to_s
	"#{name} - #{hostname}:#{port}"
end

#to_ssh_configObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/host.rb', line 33

def to_ssh_config
	f = ""
	f << "Host #{name}\n"
	f << "  Hostname #{hostname}\n"
    f << "  Port #{port}\n"
    @params.each do |k,v|
    	f << "  #{k} #{v}\n"
    end
    f
end