class Warren::Callback::BroadcastAssociatedWithWarren

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. @see guides.rubyonrails.org/active_record_callbacks.html#callback-classes

Attributes

associations[R]
handler[R]

Public Class Methods

new(associations, handler:) click to toggle source

Creates the callback object

@param handler [Warren::Handler] The handler to take the messaged (unused) @param associations [Array<Symbol>] An array of symbols reflecting the

names of associations
# File lib/warren/callback/broadcast_associated_with_warren.rb, line 20
def initialize(associations, handler:)
  @associations = associations
  @handler = handler
end

Public Instance Methods

after_save(record) click to toggle source

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

@return [void]

# 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