Module: Browserctl::Recording::State
- Defined in:
- lib/browserctl/recording/state.rb
Overview
Singleton over the on-disk marker (STATE_FILE) that tracks which
recording, if any, is currently active. Carved out of Recording so
the facade stays focused on dispatch.
Class Method Summary collapse
-
.active ⇒ Object
Returns the active recording name, or nil when no marker exists.
-
.clear! ⇒ Object
Removes the marker.
-
.write(name) ⇒ Object
Writes the marker for
name.
Class Method Details
.active ⇒ Object
Returns the active recording name, or nil when no marker exists.
Reads the constant lazily so RSpec stub_const calls on the parent
Recording::STATE_FILE continue to take effect.
18 19 20 21 |
# File 'lib/browserctl/recording/state.rb', line 18 def active path = Browserctl::Recording::STATE_FILE File.exist?(path) ? File.read(path).strip : nil end |
.clear! ⇒ Object
Removes the marker. Raises Browserctl::Error when no recording is active. The message is preserved verbatim from the pre-split facade so existing specs and CLI surfaces stay stable.
35 36 37 38 39 40 41 |
# File 'lib/browserctl/recording/state.rb', line 35 def clear! name = active raise Browserctl::Error, "no active recording — run: browserctl recording start <name>" unless name File.unlink(Browserctl::Recording::STATE_FILE) name end |
.write(name) ⇒ Object
Writes the marker for name. Caller is responsible for any
additional setup (e.g. log initialisation).
25 26 27 28 29 30 |
# File 'lib/browserctl/recording/state.rb', line 25 def write(name) path = Browserctl::Recording::STATE_FILE FileUtils.mkdir_p(File.dirname(path)) File.write(path, name) name end |