Class: Warren::Callback::BroadcastWithWarren

Inherits:
Object
  • Object
show all
Defined in:
lib/warren/callback/broadcast_with_warren.rb

Overview

Warren::Callback::BroadcastWithWarren is a Callback class which is used to handle message broadcast of ActiveRecord::Base objects on commit

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(handler:, message_class: Warren::Message::Short) ⇒ BroadcastWithWarren

Creates the callback object

Parameters:

  • handler (Warren::Handler)

    The handler to take the messaged

  • message_class (Warren::Message) (defaults to: Warren::Message::Short)

    The adaptor to render the messages



20
21
22
23
# File 'lib/warren/callback/broadcast_with_warren.rb', line 20

def initialize(handler:, message_class: Warren::Message::Short)
  @handler = handler
  @message_class = message_class
end

Instance Attribute Details

#handlerObject (readonly)

Returns the value of attribute handler.



12
13
14
# File 'lib/warren/callback/broadcast_with_warren.rb', line 12

def handler
  @handler
end

#message_classObject (readonly)

Returns the value of attribute message_class.



12
13
14
# File 'lib/warren/callback/broadcast_with_warren.rb', line 12

def message_class
  @message_class
end

Instance Method Details

#after_commit(record) ⇒ Object



25
26
27
28
29
30
# File 'lib/warren/callback/broadcast_with_warren.rb', line 25

def after_commit(record)
  # Message rendering is slow in some cases. This broadcasts an initial
  # lightweight message which can be picked up and rendered asynchronously
  # Borrows connection as per #broadcast
  handler << message_class.new(record)
end