Class: RakeAudit::Adapters::Base
- Inherits:
-
Object
- Object
- RakeAudit::Adapters::Base
- Defined in:
- lib/rake_audit/adapters/base.rb
Overview
Abstract storage adapter defining the full persistence and query contract.
Every concrete adapter must implement #save. Adapters that back the Web UI must also implement the six query methods below; the default implementations raise NotImplementedError so omissions surface loudly.
Direct Known Subclasses
Instance Method Summary collapse
-
#average_duration_ms ⇒ Float?
Mean
duration_msacross all stored executions, ornilwhen empty. -
#count ⇒ Integer
Total number of stored executions.
-
#count_by_status(status) ⇒ Integer
Number of executions whose
statusequalsstatus. -
#find(id) ⇒ Object
Return a single execution record by ID.
-
#query(filters: {}, page: nil, per_page: 25) ⇒ Object
Return a kaminari-paginated, filtered, newest-first collection.
-
#save(record) ⇒ Object
Persist a TaskExecutionRecord.
-
#stats ⇒ Hash
All five dashboard metrics in a single call.
-
#top_failed_tasks(limit: 10) ⇒ Array<Array(String, Integer)>
The
limittask names with the most failures, ordered descending.
Instance Method Details
#average_duration_ms ⇒ Float?
Mean duration_ms across all stored executions, or nil when empty.
61 62 63 |
# File 'lib/rake_audit/adapters/base.rb', line 61 def average_duration_ms raise NotImplementedError, "#{self.class}#average_duration_ms is not implemented" end |
#count ⇒ Integer
Total number of stored executions.
44 45 46 |
# File 'lib/rake_audit/adapters/base.rb', line 44 def count raise NotImplementedError, "#{self.class}#count is not implemented" end |
#count_by_status(status) ⇒ Integer
Number of executions whose status equals status.
53 54 55 |
# File 'lib/rake_audit/adapters/base.rb', line 53 def count_by_status(status) raise NotImplementedError, "#{self.class}#count_by_status is not implemented" end |
#find(id) ⇒ Object
Return a single execution record by ID.
36 37 38 |
# File 'lib/rake_audit/adapters/base.rb', line 36 def find(id) raise NotImplementedError, "#{self.class}#find is not implemented" end |
#query(filters: {}, page: nil, per_page: 25) ⇒ Object
Return a kaminari-paginated, filtered, newest-first collection.
27 28 29 |
# File 'lib/rake_audit/adapters/base.rb', line 27 def query(filters: {}, page: nil, per_page: 25) raise NotImplementedError, "#{self.class}#query is not implemented" end |
#save(record) ⇒ Object
Persist a TaskExecutionRecord.
15 16 17 |
# File 'lib/rake_audit/adapters/base.rb', line 15 def save(record) raise NotImplementedError, "#{self.class}#save is not implemented" end |
#stats ⇒ Hash
All five dashboard metrics in a single call.
The default implementation delegates to the five individual methods, which is efficient for SQL-backed adapters (five fast queries). Adapters whose individual methods are expensive (e.g. Redis, which reads the full list per call) should override this to compute everything in one pass.
83 84 85 86 87 88 89 90 91 |
# File 'lib/rake_audit/adapters/base.rb', line 83 def stats { total: count, success_count: count_by_status('success'), failure_count: count_by_status('failure'), average_duration_ms: average_duration_ms, top_failed_tasks: top_failed_tasks } end |
#top_failed_tasks(limit: 10) ⇒ Array<Array(String, Integer)>
The limit task names with the most failures, ordered descending.
70 71 72 |
# File 'lib/rake_audit/adapters/base.rb', line 70 def top_failed_tasks(limit: 10) raise NotImplementedError, "#{self.class}#top_failed_tasks is not implemented" end |