Module: Sequent::Core::SerializesCommand

Included in:
CommandRecord
Defined in:
lib/sequent/core/command_record.rb

Instance Method Summary collapse

Instance Method Details

#commandObject



8
9
10
11
# File 'lib/sequent/core/command_record.rb', line 8

def command
  args = Sequent::Core::Oj.strict_load(command_json)
  Class.const_get(command_type.to_sym).deserialize_from_json(args)
end

#command=(command) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/sequent/core/command_record.rb', line 13

def command=(command)
  self.created_at = command.created_at
  self.aggregate_id = command.aggregate_id if command.respond_to? :aggregate_id
  self.organization_id = command.organization_id if command.respond_to? :organization_id
  self.user_id = command.user_id if command.respond_to? :user_id
  self.command_type = command.class.name
  self.command_json = Sequent::Core::Oj.dump(command.attributes)
  self.event_aggregate_id = command.event_aggregate_id if command.respond_to? :event_aggregate_id
  self.event_sequence_number = command.event_sequence_number if command.respond_to? :event_sequence_number
end