Class: EventStoreClient::Client
- Inherits:
-
Object
- Object
- EventStoreClient::Client
- Includes:
- Configuration
- Defined in:
- lib/event_store_client/client.rb
Constant Summary collapse
- NoCallMethodOnSubscriber =
Class.new(StandardError)
- WrongExpectedEventVersion =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#connection ⇒ Object
rubocop:enable Metrics/CyclomaticComplexity.
Instance Method Summary collapse
-
#link_to(stream:, events:, options: {}) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity.
- #listen(wait: false) ⇒ Object
- #publish(stream:, events:, options: {}) ⇒ Object
- #read(stream, options: {}) ⇒ Object
- #subscribe(subscriber, to: [], options: {}) ⇒ Object
- #subscribe_to_all(subscriber, filter = nil) ⇒ Object
Methods included from Configuration
Instance Attribute Details
#connection ⇒ Object
rubocop:enable Metrics/CyclomaticComplexity
51 52 53 |
# File 'lib/event_store_client/client.rb', line 51 def connection @connection end |
Instance Method Details
#link_to(stream:, events:, options: {}) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity
41 42 43 44 45 46 47 48 |
# File 'lib/event_store_client/client.rb', line 41 def link_to(stream:, events:, options: {}) raise ArgumentError if !stream || stream == '' raise ArgumentError if events.nil? || (events.is_a?(Array) && events.empty?) res = connection.link_to(stream, events, options: ) raise WrongExpectedEventVersion.new(e.) if res.failure? res.success? end |
#listen(wait: false) ⇒ Object
36 37 38 |
# File 'lib/event_store_client/client.rb', line 36 def listen(wait: false) broker.call(@subscriptions, wait: wait) end |
#publish(stream:, events:, options: {}) ⇒ Object
12 13 14 15 |
# File 'lib/event_store_client/client.rb', line 12 def publish(stream:, events:, options: {}) res = connection.append_to_stream(stream, events, options: ) raise WrongExpectedEventVersion.new(e.) if res.failure? end |
#read(stream, options: {}) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/event_store_client/client.rb', line 17 def read(stream, options: {}) if [:all] connection.read_all_from_stream(stream, options: ) else connection.read(stream, options: ) end end |
#subscribe(subscriber, to: [], options: {}) ⇒ Object
25 26 27 28 |
# File 'lib/event_store_client/client.rb', line 25 def subscribe(subscriber, to: [], options: {}) raise NoCallMethodOnSubscriber unless subscriber.respond_to?(:call) @subscriptions.create(subscriber, to, options: ) end |
#subscribe_to_all(subscriber, filter = nil) ⇒ Object
30 31 32 33 34 |
# File 'lib/event_store_client/client.rb', line 30 def subscribe_to_all(subscriber, filter=nil) raise NoCallMethodOnSubscriber unless subscriber.respond_to?(:call) @subscriptions.create_or_load(subscriber, filter: filter) end |