Class: Tracekit::LocalUIDetector
- Inherits:
-
Object
- Object
- Tracekit::LocalUIDetector
- 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
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
-
#initialize(port = 9999) ⇒ LocalUIDetector
constructor
A new instance of LocalUIDetector.
-
#local_ui_endpoint ⇒ String?
Get the local UI endpoint if running.
-
#local_ui_running? ⇒ Boolean
Check if local UI is running by hitting the health endpoint.
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
#port ⇒ Object (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_endpoint ⇒ String?
Get the local UI endpoint if 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
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 |