Class: Dash::Report::History

Inherits:
Object
  • Object
show all
Defined in:
lib/dash/report/history.rb

Overview

The saved reports for one destination, newest first.

Everything here is best-effort by design: the directory is the operator's, a report may be half-written by a deploy that was killed mid-flush, and a future dash may write a schema this one does not know. None of that is worth a word on a deploy, so an unreadable file is skipped rather than reported.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(directory, destination: nil) ⇒ History

Returns a new instance of History.



12
13
14
15
# File 'lib/dash/report/history.rb', line 12

def initialize(directory, destination: nil)
  @directory = directory
  @destination = destination
end

Instance Attribute Details

#destination ⇒ Object (readonly)

Returns the value of attribute destination.



10
11
12
# File 'lib/dash/report/history.rb', line 10

def destination
  @destination
end

#directory ⇒ Object (readonly)

Returns the value of attribute directory.



10
11
12
# File 'lib/dash/report/history.rb', line 10

def directory
  @directory
end

Instance Method Details

#any? ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/dash/report/history.rb', line 21

def any?
  documents.any?
end

#prune(count) ⇒ Object

Keeps the newest count reports of this destination and deletes the rest. Other destinations are left alone: they have their own budget, and a staging deploy must not age out production's history.



28
29
30
31
32
33
34
# File 'lib/dash/report/history.rb', line 28

def prune(count)
  entries.drop(count).each do |path, _document|
    File.delete(path)
  rescue SystemCallError
    nil
  end
end

#recent(count) ⇒ Object



17
18
19
# File 'lib/dash/report/history.rb', line 17

def recent(count)
  documents.first(count)
end