Class: Tracekit::LocalUI::Detector

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

Overview

Detects if TraceKit Local UI is running and provides the endpoint

Instance Method Summary collapse

Constructor Details

#initialize(port = 9999) ⇒ Detector

Returns a new instance of Detector.



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

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

Instance Method Details

#endpointString?

Gets the Local UI endpoint if it’s running, otherwise nil

Returns:

  • (String, nil)

    The endpoint or nil



25
26
27
# File 'lib/tracekit/local_ui/detector.rb', line 25

def endpoint
  running? ? "http://localhost:#{@port}" : nil
end

#running?Boolean

Checks if Local UI is running by attempting a health check

Returns:

  • (Boolean)

    true if Local UI is running



15
16
17
18
19
20
21
# File 'lib/tracekit/local_ui/detector.rb', line 15

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