Class: Aggro::Subscription

Inherits:
Object
  • Object
show all
Defined in:
lib/aggro/subscription.rb

Overview

Private: Handles invoking events on a subscriber object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(topic, subscriber, namespace, filters, at_version) ⇒ Subscription

Returns a new instance of Subscription.



6
7
8
9
10
11
12
13
# File 'lib/aggro/subscription.rb', line 6

def initialize(topic, subscriber, namespace, filters, at_version)
  @topic = topic
  @subscriber = subscriber
  @namespace = namespace
  @filters = filters
  @at_version = at_version
  @canceled = false
end

Instance Attribute Details

#caught_upObject (readonly)

Returns the value of attribute caught_up.



4
5
6
# File 'lib/aggro/subscription.rb', line 4

def caught_up
  @caught_up
end

Instance Method Details

#cancelObject



15
16
17
18
# File 'lib/aggro/subscription.rb', line 15

def cancel
  Aggro.event_bus.unsubscribe @topic, self unless @canceled
  @canceled = true
end

#handle_event(event) ⇒ Object



20
21
22
23
24
# File 'lib/aggro/subscription.rb', line 20

def handle_event(event)
  return if @canceled

  invoke(event) if handles_event?(event) && matches_filter?(event)
end

#notify_subscription_caught_upObject



26
27
28
29
30
31
32
# File 'lib/aggro/subscription.rb', line 26

def notify_subscription_caught_up
  @caught_up = true

  return unless @subscriber.handles_event? :caught_up, @namespace

  @subscriber.send "#{@namespace}_caught_up"
end