Class: Browsable::AuditLog
- Inherits:
-
Object
- Object
- Browsable::AuditLog
- Defined in:
- lib/browsable/audit_log.rb
Overview
Thread-safe, in-memory accumulator for responses observed by the runtime middleware. Recording is per-request; analysis is one-shot at suite end.
A single global instance lives at ‘Browsable.audit_log`. Tests can replace it (or call `#clear`) for isolation. Nothing in this class invokes an analyzer — recording must be cheap and side-effect-free.
Defined Under Namespace
Classes: Entry
Instance Method Summary collapse
-
#asset_path_universe ⇒ Object
The deduplicated union of every resolved asset path seen across all entries — what TestReport hands to stylelint and eslint in one go.
- #clear ⇒ Object
- #empty? ⇒ Boolean
- #entries ⇒ Object
-
#entries_loading(asset_path) ⇒ Object
Every entry whose response loaded the given asset path.
-
#initialize ⇒ AuditLog
constructor
A new instance of AuditLog.
- #record(endpoint:, request_path:, policy:, html:, asset_paths:, inline_blocks:) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize ⇒ AuditLog
Returns a new instance of AuditLog.
28 29 30 |
# File 'lib/browsable/audit_log.rb', line 28 def initialize @entries = Concurrent::Array.new end |
Instance Method Details
#asset_path_universe ⇒ Object
The deduplicated union of every resolved asset path seen across all entries — what TestReport hands to stylelint and eslint in one go.
58 59 60 61 62 63 64 65 66 |
# File 'lib/browsable/audit_log.rb', line 58 def asset_path_universe paths = Set.new @entries.each do |entry| entry.asset_paths.each do |ref| paths << ref.resolved_path if ref.resolved_path end end paths end |
#clear ⇒ Object
76 77 78 |
# File 'lib/browsable/audit_log.rb', line 76 def clear @entries.clear end |
#empty? ⇒ Boolean
48 49 50 |
# File 'lib/browsable/audit_log.rb', line 48 def empty? @entries.empty? end |
#entries ⇒ Object
44 45 46 |
# File 'lib/browsable/audit_log.rb', line 44 def entries @entries.to_a end |
#entries_loading(asset_path) ⇒ Object
Every entry whose response loaded the given asset path. Used to attribute an end-of-suite finding back to the endpoints that triggered it.
70 71 72 73 74 |
# File 'lib/browsable/audit_log.rb', line 70 def entries_loading(asset_path) @entries.select do |entry| entry.asset_paths.any? { |ref| ref.resolved_path == asset_path } end end |
#record(endpoint:, request_path:, policy:, html:, asset_paths:, inline_blocks:) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/browsable/audit_log.rb', line 32 def record(endpoint:, request_path:, policy:, html:, asset_paths:, inline_blocks:) @entries << Entry.new( endpoint: endpoint, request_path: request_path, policy: policy, html: html, asset_paths: asset_paths, inline_blocks: inline_blocks, recorded_at: Time.now ) end |
#size ⇒ Object
52 53 54 |
# File 'lib/browsable/audit_log.rb', line 52 def size @entries.size end |