Class: Terminus::Controller
- Inherits:
-
Object
- Object
- Terminus::Controller
- Includes:
- Timeouts
- Defined in:
- lib/terminus/controller.rb
Constant Summary
Constants included from Timeouts
Instance Attribute Summary collapse
-
#dock_host ⇒ Object
Returns the value of attribute dock_host.
Instance Method Summary collapse
- #browser(id = nil) ⇒ Object
- #browser=(params) ⇒ Object
- #drop_browser(browser) ⇒ Object
- #ensure_browser ⇒ Object
- #ensure_docked_browser ⇒ Object
-
#initialize ⇒ Controller
constructor
A new instance of Controller.
- #messenger ⇒ Object
- #return_to_dock ⇒ Object
Methods included from Timeouts
Constructor Details
#initialize ⇒ Controller
Returns a new instance of Controller.
7 8 9 10 11 12 |
# File 'lib/terminus/controller.rb', line 7 def initialize @connected = false @browsers = {} @ping_callbacks = [] trap('INT') { exit } end |
Instance Attribute Details
#dock_host ⇒ Object
Returns the value of attribute dock_host.
5 6 7 |
# File 'lib/terminus/controller.rb', line 5 def dock_host @dock_host end |
Instance Method Details
#browser(id = nil) ⇒ Object
14 15 16 17 |
# File 'lib/terminus/controller.rb', line 14 def browser(id = nil) return @browser if id.nil? @browsers[id] ||= Browser.new(self) end |
#browser=(params) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/terminus/controller.rb', line 19 def browser=(params) @browser = case params when :docked then @browsers.values.find { |b| b.docked? } when Browser then params when Hash then wait_with_timeout(:named_window) do @browsers.values.find { |b| b.name == params[:name] } end end end |
#drop_browser(browser) ⇒ Object
30 31 32 33 |
# File 'lib/terminus/controller.rb', line 30 def drop_browser(browser) @browsers.delete(browser.id) @browser = nil if @browser == browser end |
#ensure_browser ⇒ Object
35 36 37 38 |
# File 'lib/terminus/controller.rb', line 35 def ensure_browser ensure_connection wait_with_timeout(:browser) { @browser } end |
#ensure_docked_browser ⇒ Object
40 41 42 43 |
# File 'lib/terminus/controller.rb', line 40 def ensure_docked_browser ensure_connection wait_with_timeout(:docked_browser) { @browsers.any? { |id,b| b.docked? } } end |
#messenger ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/terminus/controller.rb', line 45 def messenger Terminus.ensure_reactor_running return @messenger if defined?(@messenger) @messenger = Faye::Client.new(Terminus.endpoint) @messenger.subscribe('/terminus/ping', &method(:accept_ping)) @messenger.subscribe('/terminus/results', &method(:accept_result)) @messenger end |
#return_to_dock ⇒ Object
56 57 58 |
# File 'lib/terminus/controller.rb', line 56 def return_to_dock @browsers.each { |id, b| b.return_to_dock } end |