Class: RubyEventStore::PubSub::Subscriptions::LocalSubscriptions

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

Instance Method Summary collapse

Constructor Details

#initializeLocalSubscriptions

Returns a new instance of LocalSubscriptions.



48
49
50
# File 'lib/ruby_event_store/pub_sub/subscriptions.rb', line 48

def initialize
  @subscriptions = Hash.new {|hsh, key| hsh[key] = [] }
end

Instance Method Details

#add(subscription, event_types) ⇒ Object



52
53
54
55
# File 'lib/ruby_event_store/pub_sub/subscriptions.rb', line 52

def add(subscription, event_types)
  event_types.each{ |type| @subscriptions[type.to_s] << subscription }
  ->() {event_types.each{ |type| @subscriptions.fetch(type.to_s).delete(subscription) } }
end

#all_for(event_type) ⇒ Object



57
58
59
# File 'lib/ruby_event_store/pub_sub/subscriptions.rb', line 57

def all_for(event_type)
  @subscriptions[event_type]
end