Class: Messenger

Inherits:
ApplicationRecord show all
Defined in:
app/models/messenger.rb

Overview

Messengers handle passing a target into a message template for rendering warehouse messages

Instance Method Summary collapse

Methods inherited from ApplicationRecord

alias_association, convert_labware_to_receptacle_for, find_by_id_or_name, find_by_id_or_name!

Methods included from Squishify

extended

Instance Method Details

#as_json(_options = {}) ⇒ Object



17
18
19
# File 'app/models/messenger.rb', line 17

def as_json(_options = {})
  { root => render_class.to_hash(target), 'lims' => configatron.amqp.lims_id! }
end

#render_classObject



9
10
11
# File 'app/models/messenger.rb', line 9

def render_class
  "Api::Messages::#{template}".constantize
end

#resendObject



28
29
30
# File 'app/models/messenger.rb', line 28

def resend
  Warren.handler << Warren::Message::Short.new(self)
end

#routing_keyObject



13
14
15
# File 'app/models/messenger.rb', line 13

def routing_key
  "message.#{root}.#{id}"
end

#templateObject



21
22
23
24
25
26
# File 'app/models/messenger.rb', line 21

def template
  # Replace IO with Io to match the class name
  # This is a consequence of the zeitwerk renaming for the message modules from IO to Io
  # This ensures that the correct class is loaded for historical messages
  read_attribute(:template).gsub(/IO$/, 'Io')
end