Class: SSHTunnel::UI::Models::Host
- Inherits:
-
Object
- Object
- SSHTunnel::UI::Models::Host
- Defined in:
- lib/ssh-hull/ui/models/host.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#identity_file ⇒ Object
Returns the value of attribute identity_file.
-
#name ⇒ Object
Returns the value of attribute name.
-
#port ⇒ Object
Returns the value of attribute port.
-
#tunnels ⇒ Object
Returns the value of attribute tunnels.
-
#user ⇒ Object
Returns the value of attribute user.
-
#uuid ⇒ Object
Returns the value of attribute uuid.
Instance Method Summary collapse
- #add_tunnel(tunnel) ⇒ Object
- #auto_start! ⇒ Object
-
#initialize(opts = {}) ⇒ Host
constructor
A new instance of Host.
- #remove_tunnel(tunnel) ⇒ Object
- #start_tunnels! ⇒ Object
- #started? ⇒ Boolean
- #stop_tunnels! ⇒ Object
- #to_hash ⇒ Object
- #to_s ⇒ Object
- #toggle_tunnels! ⇒ Object
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
#host ⇒ Object
Returns the value of attribute host.
8 9 10 |
# File 'lib/ssh-hull/ui/models/host.rb', line 8 def host @host end |
#identity_file ⇒ Object
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 |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/ssh-hull/ui/models/host.rb', line 8 def name @name end |
#port ⇒ Object
Returns the value of attribute port.
8 9 10 |
# File 'lib/ssh-hull/ui/models/host.rb', line 8 def port @port end |
#tunnels ⇒ Object
Returns the value of attribute tunnels.
8 9 10 |
# File 'lib/ssh-hull/ui/models/host.rb', line 8 def tunnels @tunnels end |
#user ⇒ Object
Returns the value of attribute user.
8 9 10 |
# File 'lib/ssh-hull/ui/models/host.rb', line 8 def user @user end |
#uuid ⇒ Object
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
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_hash ⇒ Object
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_s ⇒ Object
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 |