module InternalAffairs class PendingOperation < ::ActiveRecord::Base serialize :target_attributes self.table_name = "internal_affairs_pending_operations" validates :operation_uuid, :target_class, presence: true def target=(_target) # use separate class and attributes serialization to support non-ar cases if _target.present? self.target_class = _target.class.to_s self.target_attributes = _target.attributes_for_operation_serialization else self.target_class = self.target_attributes = nil end @target = _target end def target @target ||= load_target end private def load_target return nil if target_class.nil? target_class.constantize.load_from_operation_serialized_attributes(**target_attributes) end end end