module Deimos::ActiveRecordConsume::MessageConsumption

Methods for consuming individual messages and saving them to the database as ActiveRecord instances.

Public Instance Methods

assign_key(record, _payload, key) click to toggle source

Assign a key to a new record. @param record [ActiveRecord::Base] @param _payload [Hash] @param key [Object]

# File lib/deimos/active_record_consume/message_consumption.rb, line 23
def assign_key(record, _payload, key)
  record[record.class.primary_key] = key
end
fetch_record(klass, _payload, key) click to toggle source

Find the record specified by the given payload and key. Default is to use the primary key column and the value of the first field in the key. @param klass [Class < ActiveRecord::Base] @param _payload [Hash] @param key [Object] @return [ActiveRecord::Base]

# File lib/deimos/active_record_consume/message_consumption.rb, line 15
def fetch_record(klass, _payload, key)
  klass.unscoped.where(klass.primary_key => key).first
end