Class: Kdeploy::Host
- Inherits:
-
Object
- Object
- Kdeploy::Host
- Defined in:
- lib/kdeploy/host.rb
Overview
Host class for managing remote host configuration and connection details
Instance Attribute Summary collapse
-
#hostname ⇒ Object
readonly
Returns the value of attribute hostname.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#roles ⇒ Object
readonly
Returns the value of attribute roles.
-
#ssh_options ⇒ Object
readonly
Returns the value of attribute ssh_options.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
-
#vars ⇒ Object
readonly
Returns the value of attribute vars.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Compare hosts for equality.
-
#connection_options ⇒ Hash
Get SSH connection options.
-
#connection_string ⇒ String
Get connection string for display.
-
#has_role?(role) ⇒ Boolean
Check if host has specific role.
-
#hash ⇒ Integer
Generate hash code for host.
-
#initialize(hostname, user: nil, port: nil, ssh_options: {}, roles: [], vars: {}) ⇒ Host
constructor
A new instance of Host.
-
#inspect ⇒ String
Detailed string representation of the host.
-
#set_var(key, value) ⇒ Object
Set variable value.
-
#to_s ⇒ String
String representation of the host.
-
#var(key) ⇒ Object
Get variable value.
Constructor Details
#initialize(hostname, user: nil, port: nil, ssh_options: {}, roles: [], vars: {}) ⇒ Host
Returns a new instance of Host.
8 9 10 11 12 13 14 15 |
# File 'lib/kdeploy/host.rb', line 8 def initialize(hostname, user: nil, port: nil, ssh_options: {}, roles: [], vars: {}) @hostname = hostname @user = user || Kdeploy.configuration&.default_user || ENV.fetch('USER', nil) @port = port || Kdeploy.configuration&.default_port || 22 @ssh_options = @roles = Array(roles) @vars = vars || {} end |
Instance Attribute Details
#hostname ⇒ Object (readonly)
Returns the value of attribute hostname.
6 7 8 |
# File 'lib/kdeploy/host.rb', line 6 def hostname @hostname end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
6 7 8 |
# File 'lib/kdeploy/host.rb', line 6 def port @port end |
#roles ⇒ Object (readonly)
Returns the value of attribute roles.
6 7 8 |
# File 'lib/kdeploy/host.rb', line 6 def roles @roles end |
#ssh_options ⇒ Object (readonly)
Returns the value of attribute ssh_options.
6 7 8 |
# File 'lib/kdeploy/host.rb', line 6 def @ssh_options end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
6 7 8 |
# File 'lib/kdeploy/host.rb', line 6 def user @user end |
#vars ⇒ Object (readonly)
Returns the value of attribute vars.
6 7 8 |
# File 'lib/kdeploy/host.rb', line 6 def vars @vars end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Compare hosts for equality
69 70 71 72 73 74 75 |
# File 'lib/kdeploy/host.rb', line 69 def ==(other) return false unless other.is_a?(Host) hostname == other.hostname && user == other.user && port == other.port end |
#connection_options ⇒ Hash
Get SSH connection options
47 48 49 50 51 52 |
# File 'lib/kdeploy/host.rb', line 47 def = Kdeploy.configuration&.(@ssh_options) || @ssh_options .merge( timeout: Kdeploy.configuration&.ssh_timeout || 30 ) end |
#connection_string ⇒ String
Get connection string for display
41 42 43 |
# File 'lib/kdeploy/host.rb', line 41 def connection_string "#{@user}@#{@hostname}:#{@port}" end |
#has_role?(role) ⇒ Boolean
Check if host has specific role
20 21 22 |
# File 'lib/kdeploy/host.rb', line 20 def has_role?(role) @roles.include?(role.to_s) || @roles.include?(role.to_sym) end |
#hash ⇒ Integer
Generate hash code for host
81 82 83 |
# File 'lib/kdeploy/host.rb', line 81 def hash [hostname, user, port].hash end |
#inspect ⇒ String
Detailed string representation of the host
62 63 64 |
# File 'lib/kdeploy/host.rb', line 62 def inspect "#<Kdeploy::Host #{connection_string} roles=#{@roles} vars=#{@vars.keys}>" end |
#set_var(key, value) ⇒ Object
Set variable value
35 36 37 |
# File 'lib/kdeploy/host.rb', line 35 def set_var(key, value) @vars[key.to_s] = value end |
#to_s ⇒ String
String representation of the host
56 57 58 |
# File 'lib/kdeploy/host.rb', line 56 def to_s connection_string end |
#var(key) ⇒ Object
Get variable value
27 28 29 |
# File 'lib/kdeploy/host.rb', line 27 def var(key) @vars[key.to_s] || @vars[key.to_sym] end |