Module: Philiprehberger::AuditTrail::Summarizable

Included in:
Tracker
Defined in:
lib/philiprehberger/audit_trail/summarizable.rb

Overview

Summary aggregation for audit events.

Constant Summary collapse

VALID_GROUP_KEYS =
%i[actor action entity_id].freeze

Instance Method Summary collapse

Instance Method Details

#summary(group_by:) ⇒ Hash

Aggregate event counts grouped by the specified field.

Parameters:

  • group_by (Symbol)

    :actor, :action, or :entity_id

Returns:

  • (Hash)

    counts keyed by field value



13
14
15
16
17
18
19
# File 'lib/philiprehberger/audit_trail/summarizable.rb', line 13

def summary(group_by:)
  validate_group_key!(group_by)
  @store.all.each_with_object(Hash.new(0)) do |event, counts|
    key = event.public_send(group_by)
    counts[key] += 1
  end
end