Class: OpenLoam::EventRecord

Inherits:
TenantRecord
  • Object
show all
Defined in:
app/models/open_loam/event_record.rb

Overview

One captured domain event (see OpenLoam::EventLog). Where OpenLoam::EventDelivery records that a durable subscriber was told, this records that the thing happened at all.

Append-only: a persisted row is readonly, so retention must delete_all rather than destroy.

Instance Method Summary collapse

Instance Method Details

#payload_hash ⇒ Object

The stored payload as a Hash regardless of adapter (Postgres jsonb returns a Hash; a text/json column may hand back a String).



33
34
35
36
37
38
39
40
# File 'app/models/open_loam/event_record.rb', line 33

def payload_hash
  value = self[:payload]
  return value if value.is_a?(Hash)

  JSON.parse(value.to_s.presence || "{}")
rescue JSON::ParserError
  {}
end

#readonly? ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'app/models/open_loam/event_record.rb', line 27

def readonly?
  persisted?
end