Class: Euston::EventStore::Commit
- Inherits:
-
Object
- Object
- Euston::EventStore::Commit
- Includes:
- Persistence::Mongodb::MongoCommit
- Defined in:
- lib/euston-eventstore/commit.rb,
lib/euston-eventstore/persistence/mongodb/mongo_commit.rb
Overview
Represents a series of events which have been fully committed as a single unit and which apply to the stream indicated.
Instance Attribute Summary collapse
-
#commands ⇒ Object
readonly
Gets the collection of command messages to be committed as a single unit.
-
#commit_id ⇒ Object
readonly
Gets the value which uniquely identifies the commit within the stream.
-
#commit_sequence ⇒ Object
readonly
Gets the value which indicates the sequence (or position) in the stream to which this commit applies.
-
#commit_timestamp ⇒ Object
readonly
Gets the point in time at which the commit was persisted.
-
#events ⇒ Object
readonly
Gets the collection of event messages to be committed as a single unit.
-
#headers ⇒ Object
readonly
Gets the metadata which provides additional, unstructured information about this commit.
-
#stream_id ⇒ Object
readonly
Gets the value which uniquely identifies the stream to which the commit belongs.
-
#stream_revision ⇒ Object
readonly
Gets the value which indicates the revision of the most recent event in the stream to which this commit applies.
Attributes included from Persistence::Mongodb::MongoCommit
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(hash) ⇒ Commit
constructor
A new instance of Commit.
- #to_hash ⇒ Object
Methods included from Persistence::Mongodb::MongoCommit
from_hash, #mongo_initialize, #to_id_query, #to_mongo_commit, #to_mongo_hash
Constructor Details
#initialize(hash) ⇒ Commit
Returns a new instance of Commit.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/euston-eventstore/commit.rb', line 6 def initialize(hash) defaults = { :stream_id => nil, :stream_revision => 1, :commit_id => nil, :commit_sequence => 1, :commit_timestamp => Time.now.utc, :headers => OpenStruct.new, :events => [], :commands => [] } values = defaults.merge hash defaults.keys.each { |key| instance_variable_set "@#{key}", values[key] } end |
Instance Attribute Details
#commands ⇒ Object (readonly)
Gets the collection of command messages to be committed as a single unit.
55 56 57 |
# File 'lib/euston-eventstore/commit.rb', line 55 def commands @commands end |
#commit_id ⇒ Object (readonly)
Gets the value which uniquely identifies the commit within the stream.
40 41 42 |
# File 'lib/euston-eventstore/commit.rb', line 40 def commit_id @commit_id end |
#commit_sequence ⇒ Object (readonly)
Gets the value which indicates the sequence (or position) in the stream to which this commit applies.
43 44 45 |
# File 'lib/euston-eventstore/commit.rb', line 43 def commit_sequence @commit_sequence end |
#commit_timestamp ⇒ Object (readonly)
Gets the point in time at which the commit was persisted.
46 47 48 |
# File 'lib/euston-eventstore/commit.rb', line 46 def @commit_timestamp end |
#events ⇒ Object (readonly)
Gets the collection of event messages to be committed as a single unit.
52 53 54 |
# File 'lib/euston-eventstore/commit.rb', line 52 def events @events end |
#headers ⇒ Object (readonly)
Gets the metadata which provides additional, unstructured information about this commit.
49 50 51 |
# File 'lib/euston-eventstore/commit.rb', line 49 def headers @headers end |
#stream_id ⇒ Object (readonly)
Gets the value which uniquely identifies the stream to which the commit belongs.
34 35 36 |
# File 'lib/euston-eventstore/commit.rb', line 34 def stream_id @stream_id end |
#stream_revision ⇒ Object (readonly)
Gets the value which indicates the revision of the most recent event in the stream to which this commit applies.
37 38 39 |
# File 'lib/euston-eventstore/commit.rb', line 37 def stream_revision @stream_revision end |
Class Method Details
.empty?(attempt) ⇒ Boolean
62 63 64 |
# File 'lib/euston-eventstore/commit.rb', line 62 def empty?(attempt) attempt.nil? || attempt.events.empty? end |
.has_identifier?(attempt) ⇒ Boolean
66 67 68 |
# File 'lib/euston-eventstore/commit.rb', line 66 def has_identifier?(attempt) !(attempt.stream_id.nil? || attempt.commit_id.nil?) end |
.valid?(attempt) ⇒ Boolean
70 71 72 73 74 75 76 77 78 |
# File 'lib/euston-eventstore/commit.rb', line 70 def valid?(attempt) raise ArgumentError.new('The commit must not be nil.') if attempt.nil? raise ArgumentError.new('The commit must be uniquely identified.') unless Commit.has_identifier? attempt raise ArgumentError.new('The commit sequence must be a positive number.') unless attempt.commit_sequence > 0 raise ArgumentError.new('The stream revision must be a positive number.') unless attempt.stream_revision > 0 raise ArgumentError.new('The stream revision must always be greater than or equal to the commit sequence.') if (attempt.stream_revision < attempt.commit_sequence) true end |
Instance Method Details
#==(other) ⇒ Object
57 58 59 |
# File 'lib/euston-eventstore/commit.rb', line 57 def ==(other) (other.is_a? Commit) && (@stream_id == other.stream_id) && (@commit_id == other.commit_id) end |
#to_hash ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/euston-eventstore/commit.rb', line 21 def to_hash { :stream_id => stream_id, :stream_revision => stream_revision, :commit_id => commit_id, :commit_sequence => commit_sequence, :commit_timestamp => , :headers => headers.is_a?(OpenStruct) ? headers.instance_variable_get(:@table) : headers, :events => events, :commands => commands } end |