Class: Tomo::Host
- Inherits:
-
Object
- Object
- Tomo::Host
- Includes:
- Testing::HostExtensions
- Defined in:
- lib/tomo/host.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#as_privileged ⇒ Object
readonly
Returns the value of attribute as_privileged.
-
#log_prefix ⇒ Object
readonly
Returns the value of attribute log_prefix.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#roles ⇒ Object
readonly
Returns the value of attribute roles.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Attributes included from Testing::HostExtensions
#helper_values, #mocks, #release, #scripts
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(address:, port: nil, log_prefix: nil, roles: nil, user: nil, privileged_user: "root") ⇒ Host
constructor
A new instance of Host.
- #to_s ⇒ Object
- #to_ssh_args ⇒ Object
- #with_log_prefix(prefix) ⇒ Object
Methods included from Testing::HostExtensions
Constructor Details
#initialize(address:, port: nil, log_prefix: nil, roles: nil, user: nil, privileged_user: "root") ⇒ Host
Returns a new instance of Host.
18 19 20 21 22 23 24 25 26 |
# File 'lib/tomo/host.rb', line 18 def initialize(address:, port: nil, log_prefix: nil, roles: nil, user: nil, privileged_user: "root") @user = user.freeze @port = (port || 22).to_i.freeze @address = address.freeze @log_prefix = log_prefix.freeze @roles = Array(roles).map(&:freeze).freeze @as_privileged = privileged_copy(privileged_user) freeze end |
Instance Attribute Details
#address ⇒ Object (readonly)
Returns the value of attribute address.
8 9 10 |
# File 'lib/tomo/host.rb', line 8 def address @address end |
#as_privileged ⇒ Object (readonly)
Returns the value of attribute as_privileged.
8 9 10 |
# File 'lib/tomo/host.rb', line 8 def as_privileged @as_privileged end |
#log_prefix ⇒ Object (readonly)
Returns the value of attribute log_prefix.
8 9 10 |
# File 'lib/tomo/host.rb', line 8 def log_prefix @log_prefix end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
8 9 10 |
# File 'lib/tomo/host.rb', line 8 def port @port end |
#roles ⇒ Object (readonly)
Returns the value of attribute roles.
8 9 10 |
# File 'lib/tomo/host.rb', line 8 def roles @roles end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
8 9 10 |
# File 'lib/tomo/host.rb', line 8 def user @user end |
Class Method Details
.parse(host) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/tomo/host.rb', line 10 def self.parse(host, **) host = host.to_s.strip user, address = host.match(PATTERN).captures raise ArgumentError, "host cannot be blank" if address.empty? new(user:, address:, **) end |
Instance Method Details
#to_s ⇒ Object
34 35 36 37 38 |
# File 'lib/tomo/host.rb', line 34 def to_s str = user ? "#{user}@#{address}" : address str += ":#{port}" unless port == 22 str end |
#to_ssh_args ⇒ Object
40 41 42 43 44 |
# File 'lib/tomo/host.rb', line 40 def to_ssh_args args = [user ? "#{user}@#{address}" : address] args.push("-p", port.to_s) unless port == 22 args end |
#with_log_prefix(prefix) ⇒ Object
28 29 30 31 32 |
# File 'lib/tomo/host.rb', line 28 def with_log_prefix(prefix) copy = dup copy.instance_variable_set(:@log_prefix, prefix) copy.freeze end |