Class: Warren::Callback::BroadcastAssociatedWithWarren
- Inherits:
-
Object
- Object
- Warren::Callback::BroadcastAssociatedWithWarren
- 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
-
#associations ⇒ Object
readonly
Returns the value of attribute associations.
-
#handler ⇒ Object
readonly
Returns the value of attribute handler.
Instance Method Summary collapse
-
#after_save(record) ⇒ void
After save callback: configured via broadcasts_associated_with_warren Adds any associated records to the transaction, ensuring their after commit methods will fire.
-
#initialize(associations, handler:) ⇒ BroadcastAssociatedWithWarren
constructor
Creates the callback object.
Constructor Details
#initialize(associations, handler:) ⇒ BroadcastAssociatedWithWarren
Creates the callback object
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
#associations ⇒ Object (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 |
#handler ⇒ Object (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 |