Class: SimpleCov::CLI::Watch::LiveReport
- Inherits:
-
Object
- Object
- SimpleCov::CLI::Watch::LiveReport
- 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
- #broadcast(event = "reload") ⇒ Object
-
#initialize(dir) ⇒ LiveReport
constructor
A new instance of LiveReport.
- #routes ⇒ Object
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 |
#routes ⇒ Object
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 |