Class: ColdStorage::Report
- Inherits:
-
Object
- Object
- ColdStorage::Report
- Defined in:
- lib/cold_storage/report.rb
Overview
Human readable status of every archivable model: what its rule is, how many rows are waiting, how many are already archived, when it last ran.
Constant Summary collapse
- HEADERS =
['Model', 'Rule', 'Pending', 'Archived', 'Last run'].freeze
Instance Method Summary collapse
-
#initialize(models: nil, counts: true) ⇒ Report
constructor
A new instance of Report.
- #rows ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(models: nil, counts: true) ⇒ Report
Returns a new instance of Report.
9 10 11 12 |
# File 'lib/cold_storage/report.rb', line 9 def initialize(models: nil, counts: true) @models = models || ColdStorage.models @counts = counts end |
Instance Method Details
#rows ⇒ Object
14 15 16 |
# File 'lib/cold_storage/report.rb', line 14 def rows @rows ||= @models.map { |model| row_for(model) } end |
#to_s ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/cold_storage/report.rb', line 18 def to_s table = [HEADERS, *rows] widths = HEADERS.each_index.map { |i| table.map { |row| row[i].to_s.length }.max } separator = widths.map { |width| '-' * width }.join('-+-') lines = table.map { |row| row.each_with_index.map { |cell, i| cell.to_s.ljust(widths[i]) }.join(' | ') } lines.insert(1, separator) lines.join("\n") end |