Module: ModelTransporter::NotifiesModelUpdates

Extended by:
ActiveSupport::Concern
Defined in:
lib/model_transporter/notifies_model_updates.rb

Instance Method Summary collapse

Instance Method Details

#notify_model_updates(update_type, model_state) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/model_transporter/notifies_model_updates.rb', line 27

def notify_model_updates(update_type, model_state)
  channel = instance_exec(&(self.class.notifies_model_updates_options[:channel]))
  id_key = self.public_send(self.class.notifies_model_updates_options[:id_key])

  payload = { creates: {}, updates: {}, deletes: {} }
  payload[update_type] = {
    self.class.name.pluralize.underscore => {
      id_key => model_state
    }
  }

  ModelTransporter::BatchModelUpdates.enqueue_model_updates(
    channel,
    payload
  )
end