Module: Warren::Callback::ClassMethods

Defined in:
lib/warren/callback.rb

Overview

Provides the broadcast_with_warren and broadcasts_associated_with_warren to ActiveRecord::Base classes to configure broadcast

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#associated_to_broadcastObject (readonly)

Returns the value of attribute associated_to_broadcast.



16
17
18
# File 'lib/warren/callback.rb', line 16

def associated_to_broadcast
  @associated_to_broadcast
end

#warrenObject (readonly)

Returns the value of attribute warren.



16
17
18
# File 'lib/warren/callback.rb', line 16

def warren
  @warren
end

Instance Method Details

#broadcast_with_warren(handler: Warren.handler) ⇒ void

This method returns an undefined value.

Records of this type are broadcast via RabbitMQ when a transaction is closed.



23
24
25
# File 'lib/warren/callback.rb', line 23

def broadcast_with_warren(handler: Warren.handler)
  after_commit BroadcastWithWarren.new(handler: handler)
end

#broadcasts_associated_with_warren(*associated, handler: Warren.handler) ⇒ void

This method returns an undefined value.

When records of this type are saved, broadcast the associated records once the transaction is closed. (Requires that associated record is broadcast_with_warren)

Parameters:

  • associated (Symbol, Array<Symbol>)

    One or more symbols indicating the associations to broadcast.



35
36
37
# File 'lib/warren/callback.rb', line 35

def broadcasts_associated_with_warren(*associated, handler: Warren.handler)
  after_save BroadcastAssociatedWithWarren.new(associated, handler: handler)
end