Class: Euston::EventStore::OptimisticEventStore
- Inherits:
-
Object
- Object
- Euston::EventStore::OptimisticEventStore
- Defined in:
- lib/euston-eventstore/optimistic_event_store.rb
Instance Method Summary collapse
- #add_snapshot(snapshot) ⇒ Object
- #commit(attempt) ⇒ Object
- #create_stream(stream_id) ⇒ Object
- #get_from(stream_id, min_revision, max_revision) ⇒ Object
- #get_snapshot(stream_id, max_revision = 0) ⇒ Object
- #get_snapshot_stream_pair(stream_id) ⇒ Object
- #get_streams_to_snapshot(max_threshold) ⇒ Object
-
#initialize(persistence) ⇒ OptimisticEventStore
constructor
A new instance of OptimisticEventStore.
- #instrumentation ⇒ Object
- #open_stream(options) ⇒ Object
Constructor Details
#initialize(persistence) ⇒ OptimisticEventStore
Returns a new instance of OptimisticEventStore.
4 5 6 |
# File 'lib/euston-eventstore/optimistic_event_store.rb', line 4 def initialize(persistence) @persistence = persistence end |
Instance Method Details
#add_snapshot(snapshot) ⇒ Object
13 14 15 |
# File 'lib/euston-eventstore/optimistic_event_store.rb', line 13 def add_snapshot(snapshot) @persistence.add_snapshot snapshot end |
#commit(attempt) ⇒ Object
17 18 19 20 21 |
# File 'lib/euston-eventstore/optimistic_event_store.rb', line 17 def commit(attempt) return unless Commit.valid?(attempt) && !Commit.empty?(attempt) @persistence.commit attempt end |
#create_stream(stream_id) ⇒ Object
23 24 25 26 |
# File 'lib/euston-eventstore/optimistic_event_store.rb', line 23 def create_stream(stream_id) OptimisticEventStream.new(:stream_id => stream_id, :persistence => self) end |
#get_from(stream_id, min_revision, max_revision) ⇒ Object
28 29 30 31 32 |
# File 'lib/euston-eventstore/optimistic_event_store.rb', line 28 def get_from(stream_id, min_revision, max_revision) @persistence.get_from(:stream_id => stream_id, :min_revision => min_revision, :max_revision => max_revision).to_enum end |
#get_snapshot(stream_id, max_revision = 0) ⇒ Object
34 35 36 |
# File 'lib/euston-eventstore/optimistic_event_store.rb', line 34 def get_snapshot(stream_id, max_revision = 0) @persistence.get_snapshot stream_id, validate_max_revision(max_revision) end |
#get_snapshot_stream_pair(stream_id) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/euston-eventstore/optimistic_event_store.rb', line 42 def get_snapshot_stream_pair stream_id snapshot = get_snapshot stream_id stream = open_stream :stream_id => stream_id, :snapshot => snapshot SnapshotStreamPair.new snapshot, stream end |
#get_streams_to_snapshot(max_threshold) ⇒ Object
38 39 40 |
# File 'lib/euston-eventstore/optimistic_event_store.rb', line 38 def get_streams_to_snapshot(max_threshold) @persistence.get_streams_to_snapshot max_threshold end |
#instrumentation ⇒ Object
8 9 10 11 |
# File 'lib/euston-eventstore/optimistic_event_store.rb', line 8 def instrumentation return nil unless @persistence.respond_to?(:instrumentation) @persistence.instrumentation end |
#open_stream(options) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/euston-eventstore/optimistic_event_store.rb', line 49 def open_stream() = { :stream_id => nil, :min_revision => 0, :max_revision => 0, :snapshot => nil }.merge() = .merge(:max_revision => validate_max_revision([:max_revision]), :persistence => self) if [:snapshot].nil? .delete :snapshot else .delete :stream_id .delete :min_revision end OptimisticEventStream.new end |