Class: ForemanTasks::Task::Summarizer::Record

Inherits:
Object
  • Object
show all
Defined in:
app/models/foreman_tasks/task/summarizer.rb

Overview

number of recent/total tasks for specific classification (state/result)

Direct Known Subclasses

RecordWithResult

Instance Method Summary collapse

Constructor Details

#initializeRecord

Returns a new instance of Record.



8
9
10
# File 'app/models/foreman_tasks/task/summarizer.rb', line 8

def initialize
  @data = { recent: 0, total: 0 }
end

Instance Method Details

#to_hObject



12
13
14
# File 'app/models/foreman_tasks/task/summarizer.rb', line 12

def to_h
  @data.dup
end

#update(field, counts) ⇒ Object

updates ‘field` (one of [:recent, :total]) with counts from aggregated_scope

Raises:

  • (ArgumentError)


17
18
19
20
# File 'app/models/foreman_tasks/task/summarizer.rb', line 17

def update(field, counts)
  raise ArgumentError, "Unexpected field #{field}" unless @data.key?(field)
  @data[field] = counts.sum(&:count)
end