Class: VagrantPlugins::AVF::Model::SshInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant_provider_avf/model/ssh_info.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host:, port:, username:) ⇒ SshInfo

Returns a new instance of SshInfo.



22
23
24
25
26
# File 'lib/vagrant_provider_avf/model/ssh_info.rb', line 22

def initialize(host:, port:, username:)
  @host = normalize_host(host)
  @port = normalize_port(port)
  @username = normalize_username(username)
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



5
6
7
# File 'lib/vagrant_provider_avf/model/ssh_info.rb', line 5

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



5
6
7
# File 'lib/vagrant_provider_avf/model/ssh_info.rb', line 5

def port
  @port
end

#usernameObject (readonly)

Returns the value of attribute username.



5
6
7
# File 'lib/vagrant_provider_avf/model/ssh_info.rb', line 5

def username
  @username
end

Class Method Details

.fetch_required(attributes, key) ⇒ Object

Raises:

  • (ArgumentError)


15
16
17
18
19
20
# File 'lib/vagrant_provider_avf/model/ssh_info.rb', line 15

def self.fetch_required(attributes, key)
  value = attributes[key] || attributes[key.to_sym]
  raise ArgumentError, "#{key} is required" if value.nil? || value == ""

  value
end

.from_h(attributes) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/vagrant_provider_avf/model/ssh_info.rb', line 7

def self.from_h(attributes)
  new(
    host: fetch_required(attributes, "host"),
    port: fetch_required(attributes, "port"),
    username: fetch_required(attributes, "username")
  )
end

Instance Method Details

#to_hObject



28
29
30
31
32
33
34
# File 'lib/vagrant_provider_avf/model/ssh_info.rb', line 28

def to_h
  {
    host: @host,
    port: @port,
    username: @username
  }
end