Class: RubyEventStore::Subscriptions

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_event_store/subscriptions.rb

Defined Under Namespace

Classes: GlobalSubscriptions, LocalSubscriptions, ThreadGlobalSubscriptions, ThreadLocalSubscriptions, ThreadSubscriptions

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event_type_resolver: default_event_type_resolver) ⇒ Subscriptions

Returns a new instance of Subscriptions.


7
8
9
10
11
12
# File 'lib/ruby_event_store/subscriptions.rb', line 7

def initialize(event_type_resolver: default_event_type_resolver)
  @event_type_resolver = event_type_resolver
  @local  = LocalSubscriptions.new
  @global = GlobalSubscriptions.new
  @thread = ThreadSubscriptions.new
end

Instance Attribute Details

#event_type_resolverObject (readonly)

Returns the value of attribute event_type_resolver.


34
35
36
# File 'lib/ruby_event_store/subscriptions.rb', line 34

def event_type_resolver
  @event_type_resolver
end

Instance Method Details

#add_global_subscription(subscriber) ⇒ Object


18
19
20
# File 'lib/ruby_event_store/subscriptions.rb', line 18

def add_global_subscription(subscriber)
  global.add(subscriber)
end

#add_subscription(subscriber, event_types) ⇒ Object


14
15
16
# File 'lib/ruby_event_store/subscriptions.rb', line 14

def add_subscription(subscriber, event_types)
  local.add(subscriber, resolve_event_types(event_types))
end

#add_thread_global_subscription(subscriber) ⇒ Object


26
27
28
# File 'lib/ruby_event_store/subscriptions.rb', line 26

def add_thread_global_subscription(subscriber)
  thread.global.add(subscriber)
end

#add_thread_subscription(subscriber, event_types) ⇒ Object


22
23
24
# File 'lib/ruby_event_store/subscriptions.rb', line 22

def add_thread_subscription(subscriber, event_types)
  thread.local.add(subscriber, resolve_event_types(event_types))
end

#all_for(event_type) ⇒ Object


30
31
32
# File 'lib/ruby_event_store/subscriptions.rb', line 30

def all_for(event_type)
  [local, global, thread].map{|r| r.all_for(event_type)}.reduce(&:+)
end