Class: SimpleCov::CLI::Watch::LiveReport

Inherits:
Object
  • Object
show all
Defined in:
lib/simplecov/cli/watch/live_report.rb

Overview

The live half of the watch server: an /events endpoint streaming server-sent events to every open report tab, and an index route that appends the reload listener to the artifact on the way out, so the report on disk stays byte-identical to a plain run's.

Constant Summary collapse

RELOAD_SCRIPT =
"\n<script>new EventSource('/events').onmessage = () => location.reload();</script>\n"

Instance Method Summary collapse

Constructor Details

#initialize(dir) ⇒ LiveReport

Returns a new instance of LiveReport.



13
14
15
16
17
# File 'lib/simplecov/cli/watch/live_report.rb', line 13

def initialize(dir)
  @dir = dir
  @queues = [] #: Array[Thread::Queue]
  @lock = Mutex.new
end

Instance Method Details

#broadcast(event = "reload") ⇒ Object



24
25
26
# File 'lib/simplecov/cli/watch/live_report.rb', line 24

def broadcast(event = "reload")
  with_queues { |queues| queues.each { |queue| queue << event } }
end

#routesObject



19
20
21
22
# File 'lib/simplecov/cli/watch/live_report.rb', line 19

def routes
  page = method(:page)
  {"/events" => method(:stream), "/" => page, "/index.html" => page}
end