Class: RubyEventStore::Client
- Inherits:
-
Object
- Object
- RubyEventStore::Client
- Defined in:
- lib/ruby_event_store/client.rb
Defined Under Namespace
Classes: Page
Instance Attribute Summary collapse
-
#event_broker ⇒ Object
readonly
Returns the value of attribute event_broker.
-
#repository ⇒ Object
readonly
Returns the value of attribute repository.
Instance Method Summary collapse
- #append_to_stream(stream_name, event, expected_version = :any) ⇒ Object
- #delete_stream(stream_name) ⇒ Object
-
#initialize(repository, event_broker: PubSub::Broker.new, metadata_proc: nil) ⇒ Client
constructor
A new instance of Client.
- #publish_event(event, stream_name = GLOBAL_STREAM, expected_version = :any) ⇒ Object
- #read_all_streams_backward(start, count) ⇒ Object
- #read_all_streams_forward(start, count) ⇒ Object
- #read_events_backward(stream_name, start, count) ⇒ Object
- #read_events_forward(stream_name, start, count) ⇒ Object
- #read_stream_events_backward(stream_name) ⇒ Object
- #read_stream_events_forward(stream_name) ⇒ Object
- #subscribe(subscriber, event_types, &proc) ⇒ Object
- #subscribe_to_all_events(subscriber, &proc) ⇒ Object
Constructor Details
#initialize(repository, event_broker: PubSub::Broker.new, metadata_proc: nil) ⇒ Client
Returns a new instance of Client.
3 4 5 6 7 8 9 |
# File 'lib/ruby_event_store/client.rb', line 3 def initialize(repository, event_broker: PubSub::Broker.new, metadata_proc: nil) @repository = repository @event_broker = event_broker @metadata_proc = end |
Instance Attribute Details
#event_broker ⇒ Object (readonly)
Returns the value of attribute event_broker.
10 11 12 |
# File 'lib/ruby_event_store/client.rb', line 10 def event_broker @event_broker end |
#repository ⇒ Object (readonly)
Returns the value of attribute repository.
10 11 12 |
# File 'lib/ruby_event_store/client.rb', line 10 def repository @repository end |
Instance Method Details
#append_to_stream(stream_name, event, expected_version = :any) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/ruby_event_store/client.rb', line 18 def append_to_stream(stream_name, event, expected_version = :any) validate_expected_version(stream_name, expected_version) enriched_event = (event) repository.create(enriched_event, stream_name) :ok end |
#delete_stream(stream_name) ⇒ Object
25 26 27 28 29 |
# File 'lib/ruby_event_store/client.rb', line 25 def delete_stream(stream_name) raise IncorrectStreamData if stream_name.nil? || stream_name.empty? repository.delete_stream(stream_name) :ok end |
#publish_event(event, stream_name = GLOBAL_STREAM, expected_version = :any) ⇒ Object
12 13 14 15 16 |
# File 'lib/ruby_event_store/client.rb', line 12 def publish_event(event, stream_name = GLOBAL_STREAM, expected_version = :any) append_to_stream(stream_name, event, expected_version) event_broker.notify_subscribers(event) :ok end |
#read_all_streams_backward(start, count) ⇒ Object
58 59 60 61 |
# File 'lib/ruby_event_store/client.rb', line 58 def read_all_streams_backward(start, count) page = Page.new(repository, start, count) repository.read_all_streams_backward(page.start, page.count) end |
#read_all_streams_forward(start, count) ⇒ Object
53 54 55 56 |
# File 'lib/ruby_event_store/client.rb', line 53 def read_all_streams_forward(start, count) page = Page.new(repository, start, count) repository.read_all_streams_forward(page.start, page.count) end |
#read_events_backward(stream_name, start, count) ⇒ Object
37 38 39 40 41 |
# File 'lib/ruby_event_store/client.rb', line 37 def read_events_backward(stream_name, start, count) raise IncorrectStreamData if stream_name.nil? || stream_name.empty? page = Page.new(repository, start, count) repository.read_events_backward(stream_name, page.start, page.count) end |
#read_events_forward(stream_name, start, count) ⇒ Object
31 32 33 34 35 |
# File 'lib/ruby_event_store/client.rb', line 31 def read_events_forward(stream_name, start, count) raise IncorrectStreamData if stream_name.nil? || stream_name.empty? page = Page.new(repository, start, count) repository.read_events_forward(stream_name, page.start, page.count) end |
#read_stream_events_backward(stream_name) ⇒ Object
48 49 50 51 |
# File 'lib/ruby_event_store/client.rb', line 48 def read_stream_events_backward(stream_name) raise IncorrectStreamData if stream_name.nil? || stream_name.empty? repository.read_stream_events_backward(stream_name) end |
#read_stream_events_forward(stream_name) ⇒ Object
43 44 45 46 |
# File 'lib/ruby_event_store/client.rb', line 43 def read_stream_events_forward(stream_name) raise IncorrectStreamData if stream_name.nil? || stream_name.empty? repository.read_stream_events_forward(stream_name) end |
#subscribe(subscriber, event_types, &proc) ⇒ Object
63 64 65 66 67 |
# File 'lib/ruby_event_store/client.rb', line 63 def subscribe(subscriber, event_types, &proc) event_broker.add_subscriber(subscriber, event_types).tap do |unsub| handle_subscribe(unsub, &proc) end end |
#subscribe_to_all_events(subscriber, &proc) ⇒ Object
69 70 71 72 73 |
# File 'lib/ruby_event_store/client.rb', line 69 def subscribe_to_all_events(subscriber, &proc) event_broker.add_global_subscriber(subscriber).tap do |unsub| handle_subscribe(unsub, &proc) end end |