Class: EventStoreSubscriptions::Subscriptions
- Inherits:
-
Object
- Object
- EventStoreSubscriptions::Subscriptions
- Extended by:
- MakeAtomic
- Defined in:
- lib/event_store_subscriptions/subscriptions.rb
Overview
Implements Subscription-s collection
Constant Summary collapse
- ALL_STREAM =
'$all'
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
-
#add ⇒ Array<EventStoreSubscriptions::Subscription>
Adds Subscription to the collection.
- #create(*args, **kwargs, &blk) ⇒ EventStoreSubscriptions::Subscription
-
#create_for_all(**kwargs, &blk) ⇒ EventStoreSubscriptions::Subscription
Shortcut to create a Subscription to subscribe to the ‘$all’ stream.
-
#initialize(client) ⇒ Subscriptions
constructor
A new instance of Subscriptions.
-
#listen_all ⇒ Array<EventStoreSubscriptions::Subscription>
Starts listening to all subscriptions in the collection.
-
#remove ⇒ EventStoreSubscriptions::Subscription?
Removes subscription from the collection.
-
#stop_all ⇒ Array<EventStoreSubscriptions::Subscription>
Stops listening to all subscriptions in the collection.
- #subscriptions ⇒ Array<EventStoreSubscriptions::Subscription>
Methods included from MakeAtomic
Constructor Details
#initialize(client) ⇒ Subscriptions
Returns a new instance of Subscriptions.
14 15 16 17 18 |
# File 'lib/event_store_subscriptions/subscriptions.rb', line 14 def initialize(client) @client = client @subscriptions = [] @semaphore = Mutex.new end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
9 10 11 |
# File 'lib/event_store_subscriptions/subscriptions.rb', line 9 def client @client end |
Instance Method Details
#add ⇒ Array<EventStoreSubscriptions::Subscription>
Adds Subscription to the collection
41 42 43 |
# File 'lib/event_store_subscriptions/subscriptions.rb', line 41 make_atomic def add(subscription) @subscriptions << subscription end |
#create(*args, **kwargs, &blk) ⇒ EventStoreSubscriptions::Subscription
22 23 24 25 26 27 28 29 |
# File 'lib/event_store_subscriptions/subscriptions.rb', line 22 def create(*args, **kwargs, &blk) setup = SubscriptionSetup.new(args, kwargs, blk) subscription = Subscription.new( position: position_class(args[0]).new, client: client, setup: setup ) add(subscription) subscription end |
#create_for_all(**kwargs, &blk) ⇒ EventStoreSubscriptions::Subscription
Shortcut to create a Subscription to subscribe to the ‘$all’ stream
34 35 36 |
# File 'lib/event_store_subscriptions/subscriptions.rb', line 34 def create_for_all(**kwargs, &blk) create(ALL_STREAM, **kwargs, &blk) end |
#listen_all ⇒ Array<EventStoreSubscriptions::Subscription>
Starts listening to all subscriptions in the collection
55 56 57 |
# File 'lib/event_store_subscriptions/subscriptions.rb', line 55 make_atomic def listen_all @subscriptions.each(&:listen) end |
#remove ⇒ EventStoreSubscriptions::Subscription?
Removes subscription from the collection
49 50 51 |
# File 'lib/event_store_subscriptions/subscriptions.rb', line 49 make_atomic def remove(subscription) @subscriptions.delete(subscription) end |
#stop_all ⇒ Array<EventStoreSubscriptions::Subscription>
Stops listening to all subscriptions in the collection
61 62 63 |
# File 'lib/event_store_subscriptions/subscriptions.rb', line 61 make_atomic def stop_all @subscriptions.each(&:stop_listening) end |
#subscriptions ⇒ Array<EventStoreSubscriptions::Subscription>
66 67 68 69 |
# File 'lib/event_store_subscriptions/subscriptions.rb', line 66 make_atomic def subscriptions # Duping original collection to prevent potential mutable operations over it from user's side @subscriptions.dup end |