Class: Warren::Callback::BroadcastAssociatedWithWarren

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

Overview

Warren::Callback::BroadcastWithWarren is a Callback class which is used to handle message broadcast of records associated with ActiveRecord::Base objects on save. Associated records will be queued for broadcast when the transaction is closed.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(associations, handler:) ⇒ BroadcastAssociatedWithWarren

Creates the callback object

Parameters:

  • handler (Warren::Handler)

    The handler to take the messaged (unused)

  • associations (Array<Symbol>)

    An array of symbols reflecting the names of associations



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

def initialize(associations, handler:)
  @associations = associations
  @handler = handler
end

Instance Attribute Details

#associationsObject (readonly)

Returns the value of attribute associations.



11
12
13
# File 'lib/warren/callback/broadcast_associated_with_warren.rb', line 11

def associations
  @associations
end

#handlerObject (readonly)

Returns the value of attribute handler.



11
12
13
# File 'lib/warren/callback/broadcast_associated_with_warren.rb', line 11

def handler
  @handler
end

Instance Method Details

#after_save(record) ⇒ void

This method returns an undefined value.

After save callback: configured via broadcasts_associated_with_warren Adds any associated records to the transaction, ensuring their after commit methods will fire.



32
33
34
35
36
# File 'lib/warren/callback/broadcast_associated_with_warren.rb', line 32

def after_save(record)
  associations.each do |association|
    record.send(association).try(:add_to_transaction)
  end
end