Class: RDBr::BrowserLauncher

Inherits:
Object
  • Object
show all
Defined in:
lib/rdbr/browser_launcher.rb

Constant Summary collapse

READY_TIMEOUT =
10
RETRY_INTERVAL =
0.1
WILDCARD_HOSTS =
[ '0.0.0.0', '::', '[::]' ].freeze

Class Method Summary collapse

Class Method Details

.browser_url(host:, port:) ⇒ Object



22
23
24
25
# File 'lib/rdbr/browser_launcher.rb', line 22

def browser_url(host:, port:)
  browser_host = WILDCARD_HOSTS.include?(host) ? '127.0.0.1' : host
  URI::HTTP.build(host: browser_host, port: port, path: '/').to_s
end

.open_when_ready(host:, port:, output: $stdout) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/rdbr/browser_launcher.rb', line 12

def open_when_ready(host:, port:, output: $stdout)
  url = browser_url(host: host, port: port)
  Thread.new do
    Thread.current.report_on_exception = false
    next unless wait_until_ready(url)

    output.puts "Open RDBr at #{url}" unless launch(url)
  end
end