Sha256: 952b2cc9bc48294b4b607ba25ee2c3f378456956717750f8fff92b3a6ec27753

Contents?: true

Size: 992 Bytes

Versions: 2

Compression:

Stored size: 992 Bytes

Contents

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?

      if target_attributes.is_a? Hash
        target_class.constantize.load_from_operation_serialized_attributes(**target_attributes)
      else
        target_class.constantize.load_from_operation_serialized_attributes(target_attributes)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
internal-affairs-1.2.0 lib/internal_affairs/pending_operation.rb
internal-affairs-1.1.2 lib/internal_affairs/pending_operation.rb