Class: SSHTunnel::UI::Models::Host

Inherits:
Object
  • Object
show all
Defined in:
lib/ssh-hull/ui/models/host.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Host

Returns a new instance of Host.



11
12
13
14
15
16
17
18
19
20
# File 'lib/ssh-hull/ui/models/host.rb', line 11

def initialize(opts = {})
  @uuid          = opts.fetch(:uuid) { SecureRandom.uuid }
  @name          = opts.fetch(:name, '')
  @user          = opts[:user]
  @host          = opts[:host]
  @port          = opts[:port]
  @identity_file = opts[:identity_file]
  @tunnels       = opts.fetch(:tunnels, []).map { |t_attr| Tunnel.new(t_attr.merge(parent: self)) }
  @started       = false
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



8
9
10
# File 'lib/ssh-hull/ui/models/host.rb', line 8

def host
  @host
end

#identity_fileObject

Returns the value of attribute identity_file.



8
9
10
# File 'lib/ssh-hull/ui/models/host.rb', line 8

def identity_file
  @identity_file
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/ssh-hull/ui/models/host.rb', line 8

def name
  @name
end

#portObject

Returns the value of attribute port.



8
9
10
# File 'lib/ssh-hull/ui/models/host.rb', line 8

def port
  @port
end

#tunnelsObject

Returns the value of attribute tunnels.



8
9
10
# File 'lib/ssh-hull/ui/models/host.rb', line 8

def tunnels
  @tunnels
end

#userObject

Returns the value of attribute user.



8
9
10
# File 'lib/ssh-hull/ui/models/host.rb', line 8

def user
  @user
end

#uuidObject

Returns the value of attribute uuid.



8
9
10
# File 'lib/ssh-hull/ui/models/host.rb', line 8

def uuid
  @uuid
end

Instance Method Details

#add_tunnel(tunnel) ⇒ Object



46
47
48
# File 'lib/ssh-hull/ui/models/host.rb', line 46

def add_tunnel(tunnel)
  @tunnels << tunnel
end

#auto_start!Object



56
57
58
59
# File 'lib/ssh-hull/ui/models/host.rb', line 56

def auto_start!
  started = tunnels.map(&:auto_start!)
  @started = started.any?
end

#remove_tunnel(tunnel) ⇒ Object



51
52
53
# File 'lib/ssh-hull/ui/models/host.rb', line 51

def remove_tunnel(tunnel)
  @tunnels.delete(tunnel)
end

#start_tunnels!Object



67
68
69
70
# File 'lib/ssh-hull/ui/models/host.rb', line 67

def start_tunnels!
  tunnels.each(&:start!)
  @started = true
end

#started?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/ssh-hull/ui/models/host.rb', line 62

def started?
  @started
end

#stop_tunnels!Object



73
74
75
76
# File 'lib/ssh-hull/ui/models/host.rb', line 73

def stop_tunnels!
  tunnels.each(&:stop!)
  @started = false
end

#to_hashObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ssh-hull/ui/models/host.rb', line 33

def to_hash
  {
    uuid:          uuid,
    name:          name,
    user:          user,
    host:          host,
    port:          @port,
    identity_file: identity_file,
    tunnels:       tunnels.sort_by(&:name).map(&:to_hash),
  }
end

#to_sObject



23
24
25
# File 'lib/ssh-hull/ui/models/host.rb', line 23

def to_s
  name
end

#toggle_tunnels!Object



79
80
81
82
83
84
85
# File 'lib/ssh-hull/ui/models/host.rb', line 79

def toggle_tunnels!
  if started?
    stop_tunnels!
  else
    start_tunnels!
  end
end