Class: Philiprehberger::AuditTrail::Event
- Inherits:
-
Object
- Object
- Philiprehberger::AuditTrail::Event
- Defined in:
- lib/philiprehberger/audit_trail/event.rb
Overview
Immutable data class representing a single audit event.
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#actor ⇒ Object
readonly
Returns the value of attribute actor.
-
#changes ⇒ Object
readonly
Returns the value of attribute changes.
-
#entity_id ⇒ Object
readonly
Returns the value of attribute entity_id.
-
#entity_type ⇒ Object
readonly
Returns the value of attribute entity_type.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Instance Method Summary collapse
-
#initialize(entity_id:, entity_type:, action:, **opts) ⇒ Event
constructor
A new instance of Event.
-
#to_h ⇒ Hash
Returns a hash representation of the event.
Constructor Details
#initialize(entity_id:, entity_type:, action:, **opts) ⇒ Event
Returns a new instance of Event.
16 17 18 19 20 21 22 23 24 |
# File 'lib/philiprehberger/audit_trail/event.rb', line 16 def initialize(entity_id:, entity_type:, action:, **opts) @entity_id = entity_id @entity_type = entity_type @action = action @changes = opts.fetch(:changes, {}) @actor = opts[:actor] @metadata = opts.fetch(:metadata, {}) @timestamp = opts.fetch(:timestamp, Time.now) end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
7 8 9 |
# File 'lib/philiprehberger/audit_trail/event.rb', line 7 def action @action end |
#actor ⇒ Object (readonly)
Returns the value of attribute actor.
7 8 9 |
# File 'lib/philiprehberger/audit_trail/event.rb', line 7 def actor @actor end |
#changes ⇒ Object (readonly)
Returns the value of attribute changes.
7 8 9 |
# File 'lib/philiprehberger/audit_trail/event.rb', line 7 def changes @changes end |
#entity_id ⇒ Object (readonly)
Returns the value of attribute entity_id.
7 8 9 |
# File 'lib/philiprehberger/audit_trail/event.rb', line 7 def entity_id @entity_id end |
#entity_type ⇒ Object (readonly)
Returns the value of attribute entity_type.
7 8 9 |
# File 'lib/philiprehberger/audit_trail/event.rb', line 7 def entity_type @entity_type end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
7 8 9 |
# File 'lib/philiprehberger/audit_trail/event.rb', line 7 def @metadata end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
7 8 9 |
# File 'lib/philiprehberger/audit_trail/event.rb', line 7 def @timestamp end |
Instance Method Details
#to_h ⇒ Hash
Returns a hash representation of the event.
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/philiprehberger/audit_trail/event.rb', line 29 def to_h { entity_id: @entity_id, entity_type: @entity_type, action: @action, changes: @changes, actor: @actor, metadata: @metadata, timestamp: @timestamp } end |