Class: Tracekit::LocalUIDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/tracekit/local_ui_detector.rb

Overview

Detects if TraceKit Local UI is running on the developer’s machine

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(port = 9999) ⇒ LocalUIDetector

Returns a new instance of LocalUIDetector.



11
12
13
# File 'lib/tracekit/local_ui_detector.rb', line 11

def initialize(port = 9999)
  @port = port
end

Instance Attribute Details

#portObject (readonly)

Returns the value of attribute port.



9
10
11
# File 'lib/tracekit/local_ui_detector.rb', line 9

def port
  @port
end

Instance Method Details

#local_ui_endpointString?

Get the local UI endpoint if running

Returns:

  • (String, nil)

    the endpoint URL or nil if not running



29
30
31
# File 'lib/tracekit/local_ui_detector.rb', line 29

def local_ui_endpoint
  local_ui_running? ? "http://localhost:#{@port}" : nil
end

#local_ui_running?Boolean

Check if local UI is running by hitting the health endpoint

Returns:

  • (Boolean)

    true if local UI is accessible



17
18
19
20
21
22
23
24
25
# File 'lib/tracekit/local_ui_detector.rb', line 17

def local_ui_running?
  Timeout.timeout(0.5) do
    uri = URI("http://localhost:#{@port}/api/health")
    response = Net::HTTP.get_response(uri)
    response.is_a?(Net::HTTPSuccess)
  end
rescue StandardError
  false
end