Class: ForemanTasks::Task::Summarizer::RecordWithResult

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

Overview

number of recent/total tasks for specific state + distribution across different results in ‘by_result` attribute

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRecordWithResult

Returns a new instance of RecordWithResult.



28
29
30
31
32
# File 'app/models/foreman_tasks/task/summarizer.rb', line 28

def initialize
  super
  @by_result = Hash.new { |h, k| h[k] = Record.new }
  ENSURED_RESULT_KEYS.each { |result_value| @by_result[result_value] = Record.new }
end

Instance Attribute Details

#by_resultObject (readonly)

Returns the value of attribute by_result.



26
27
28
# File 'app/models/foreman_tasks/task/summarizer.rb', line 26

def by_result
  @by_result
end

Instance Method Details

#to_hObject



34
35
36
37
38
39
# File 'app/models/foreman_tasks/task/summarizer.rb', line 34

def to_h
  by_result_hash = @by_result.each.with_object({}) do |(result, record), hash|
    hash[result] = record.to_h
  end
  super.update(by_result: by_result_hash)
end

#update(field, counts) ⇒ Object

Updates the ‘field` summary + grouping by result



42
43
44
45
46
47
# File 'app/models/foreman_tasks/task/summarizer.rb', line 42

def update(field, counts)
  super(field, counts)
  counts.group_by(&:result).each do |(result, result_counts)|
    @by_result[result].update(field, result_counts)
  end
end