module Sequent::Core::SerializesCommand
Public Instance Methods
Source
# File lib/sequent/core/command_record.rb, line 9 def command args = serialize_json? ? Sequent::Core::Oj.strict_load(command_json) : command_json Class.const_get(command_type).deserialize_from_json(args) end
Source
# File lib/sequent/core/command_record.rb, line 14 def command=(command) self.created_at = command.created_at self.aggregate_id = command.aggregate_id if command.respond_to? :aggregate_id self.user_id = command.user_id if command.respond_to? :user_id self.command_type = command.class.name self.command_json = serialize_json? ? Sequent::Core::Oj.dump(command.attributes) : command.attributes # optional attributes (here for historic reasons) # this should be moved to a configurable CommandSerializer self.event_aggregate_id = command.event_aggregate_id if serialize_attribute?(command, :event_aggregate_id) self.event_sequence_number = command.event_sequence_number if serialize_attribute?( command, :event_sequence_number, ) end
Private Instance Methods
Source
# File lib/sequent/core/command_record.rb, line 39 def serialize_attribute?(command, attribute) [self, command].all? { |obj| obj.respond_to?(attribute) } end
Source
# File lib/sequent/core/command_record.rb, line 32 def serialize_json? return true unless self.class.respond_to? :columns_hash json_column_type = self.class.columns_hash['command_json'].sql_type_metadata.type %i[json jsonb].exclude? json_column_type end