Module: Sequent::Core::SerializesEvent

Included in:
EventRecord, SnapshotRecord
Defined in:
lib/sequent/core/event_record.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(host_class) ⇒ Object



77
78
79
# File 'lib/sequent/core/event_record.rb', line 77

def self.included(host_class)
  host_class.extend(ClassMethods)
end

Instance Method Details

#eventObject



48
49
50
51
# File 'lib/sequent/core/event_record.rb', line 48

def event
  payload = serialize_json? ? Sequent::Core::Oj.strict_load(event_json) : event_json
  Class.const_get(event_type).deserialize_from_json(payload)
end

#event=(event) ⇒ Object



53
54
55
56
57
58
59
60
61
62
# File 'lib/sequent/core/event_record.rb', line 53

def event=(event)
  self.aggregate_id = event.aggregate_id
  self.sequence_number = event.sequence_number
  self.organization_id = event.organization_id if event.respond_to?(:organization_id)
  self.event_type = event.class.name
  self.created_at = event.created_at
  self.event_json = serialize_json? ? self.class.serialize_to_json(event) : event.attributes

  Sequent.configuration.event_record_hooks_class.after_serialization(self, event)
end

#serialize_json?Boolean

Returns:



81
82
83
# File 'lib/sequent/core/event_record.rb', line 81

def serialize_json?
  self.class.serialize_json?
end