Class: Tally::Archiver
- Inherits:
-
Object
- Object
- Tally::Archiver
- Defined in:
- lib/tally/archiver.rb
Class Method Summary collapse
Instance Method Summary collapse
- #archive! ⇒ Object
- #day ⇒ Object
-
#initialize(key: nil, day: nil, record: nil, type: nil) ⇒ Archiver
constructor
A new instance of Archiver.
Constructor Details
#initialize(key: nil, day: nil, record: nil, type: nil) ⇒ Archiver
Returns a new instance of Archiver.
4 5 6 7 8 9 |
# File 'lib/tally/archiver.rb', line 4 def initialize(key: nil, day: nil, record: nil, type: nil) @key = key @day = day @record = record @type = type end |
Class Method Details
.archive!(**args) ⇒ Object
36 37 38 |
# File 'lib/tally/archiver.rb', line 36 def self.archive!(**args) new(**args).archive! end |
Instance Method Details
#archive! ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/tally/archiver.rb', line 11 def archive! remove_existing_records finder.entries.each do |entry| next if entry.type.present? && !entry.record record = if entry.record Record.find_or_initialize_by(day: entry.date, key: entry.key, recordable: entry.record) else Record.find_or_initialize_by(day: entry.date, key: entry.key, recordable: nil) end record.value = entry.value record.save end enqueue_registered_calculators true end |
#day ⇒ Object
32 33 34 |
# File 'lib/tally/archiver.rb', line 32 def day @day ||= Time.current.utc.to_date end |