Module: Motion::ActionCableExtentions::DeclarativeNotifications

Includes:
Synchronization
Included in:
Channel
Defined in:
lib/motion/action_cable_extentions/declarative_notifications.rb

Overview

Provides a ‘periodically_notify(broadcasts, to:)` API that can be used to declaratively specify when a handler should be called.

Instance Method Summary collapse

Methods included from Synchronization

#perform_action, #subscribe_to_channel, #synchronize_entrypoint!, #unsubscribe_from_channel

Instance Method Details

#declarative_notificationsObject



25
26
27
# File 'lib/motion/action_cable_extentions/declarative_notifications.rb', line 25

def declarative_notifications
  @_declarative_notifications
end

#initializeObject



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/motion/action_cable_extentions/declarative_notifications.rb', line 12

def initialize(*)
  super

  # The current set of declarative notifications
  @_declarative_notifications = {}

  # The active timers for the declarative notifications
  @_declarative_notifications_timers = {}

  # The method we are routing declarative notifications to
  @_declarative_notifications_target = nil
end

#periodically_notify(notifications, via:) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/motion/action_cable_extentions/declarative_notifications.rb', line 29

def periodically_notify(notifications, via:)
  (@_declarative_notifications.to_a - notifications.to_a)
    .each do |notification, _interval|
      _shutdown_declarative_notifcation_timer(notification)
    end

  (notifications.to_a - @_declarative_notifications.to_a)
    .each do |notification, interval|
      _setup_declarative_notifcation_timer(notification, interval)
    end

  @_declarative_notifications = notifications
  @_declarative_notifications_target = via
end