Class: Qcmd::Network
- Inherits:
-
Object
- Object
- Qcmd::Network
- Defined in:
- lib/qcmd/network.rb
Overview
Browse the LAN and find open and running QLab instances.
Constant Summary collapse
- BROWSE_TIMEOUT =
2
- IPV4_MATCHER =
/\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/
Class Attribute Summary collapse
-
.browse_thread ⇒ Object
Returns the value of attribute browse_thread.
-
.machines ⇒ Object
Returns the value of attribute machines.
Class Method Summary collapse
-
.browse ⇒ Object
browse can be used alone to populate the machines list.
- .browse_and_display(options = {}) ⇒ Object
- .display(options = {}) ⇒ Object
- .find(machine_name) ⇒ Object
- .find_by_index(idx) ⇒ Object
- .init ⇒ Object
- .names ⇒ Object
Class Attribute Details
.browse_thread ⇒ Object
Returns the value of attribute browse_thread.
10 11 12 |
# File 'lib/qcmd/network.rb', line 10 def browse_thread @browse_thread end |
.machines ⇒ Object
Returns the value of attribute machines.
10 11 12 |
# File 'lib/qcmd/network.rb', line 10 def machines @machines end |
Class Method Details
.browse ⇒ Object
browse can be used alone to populate the machines list
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/qcmd/network.rb', line 17 def browse self.browse_thread = Thread.start do DNSSD.browse! '_qlab._tcp.' do |b| DNSSD.resolve b.name, b.type, b.domain do |r| self.machines << Qcmd::Machine.new(b.name, r.target, r.port) end end end sleep BROWSE_TIMEOUT Thread.kill(browse_thread) if browse_thread.alive? end |
.browse_and_display(options = {}) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/qcmd/network.rb', line 51 def browse_and_display ={} browse if ![:machine_given] || ([:machine_given] && !find([:machine_name]).nil?) display end end |
.display(options = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/qcmd/network.rb', line 31 def display ={} longest = machines.map {|m| m.name.size}.max Qcmd.print Qcmd.print "Found #{ machines.size } QLab machine#{ machines.size == 1 ? '' : 's'}" Qcmd.print machines.each_with_index do |machine, n| if Qcmd.debug? Qcmd.print "#{ n + 1 }. %-#{ longest + 2 }s %s" % [machine.name, machine.client_string] else Qcmd.print "#{ n + 1 }. %-#{ longest + 2 }s" % [machine.name] end end Qcmd.print Qcmd.print 'Type `connect "MACHINE NAME"` or `connect IP_ADDRESS` to connect to a machine' Qcmd.print end |
.find(machine_name) ⇒ Object
58 59 60 |
# File 'lib/qcmd/network.rb', line 58 def find machine_name machines.find {|m| m.name.to_s == machine_name.to_s} end |
.find_by_index(idx) ⇒ Object
62 63 64 |
# File 'lib/qcmd/network.rb', line 62 def find_by_index idx machines[idx] if idx < machines.size end |
.init ⇒ Object
12 13 14 |
# File 'lib/qcmd/network.rb', line 12 def init self.machines ||= [] end |
.names ⇒ Object
66 67 68 |
# File 'lib/qcmd/network.rb', line 66 def names machines.map(&:name) end |