Class: PgEventstore::Stream
- Inherits:
-
Object
- Object
- PgEventstore::Stream
- Defined in:
- lib/pg_eventstore/stream.rb
Constant Summary collapse
- SYSTEM_STREAM_PREFIX =
Returns a stream prefix of the system stream.
'$'
- NON_EXISTING_STREAM_REVISION =
-1 # @return [Array<String>]
- KNOWN_SYSTEM_STREAMS =
%w[$streams].freeze
Instance Attribute Summary collapse
-
#context ⇒ Object
Returns the value of attribute context.
-
#stream_id ⇒ Object
Returns the value of attribute stream_id.
-
#stream_name ⇒ Object
Returns the value of attribute stream_name.
Class Method Summary collapse
-
.all_stream ⇒ PgEventstore::Stream
Produces “all” stream instance.
- .system_stream(name) ⇒ PgEventstore::Stream
Instance Method Summary collapse
- #==(other) ⇒ Boolean
- #all_stream? ⇒ Boolean
- #deconstruct ⇒ Array (also: #to_a)
- #deconstruct_keys(keys) ⇒ Hash<Symbol => String>
- #eql?(other) ⇒ Boolean
- #hash ⇒ Integer
-
#initialize(context:, stream_name:, stream_id:) ⇒ Stream
constructor
A new instance of Stream.
-
#system? ⇒ Boolean
Determine whether a stream is reserved by ‘pg_eventstore`.
- #to_hash ⇒ Hash
Constructor Details
#initialize(context:, stream_name:, stream_id:) ⇒ Stream
Returns a new instance of Stream.
44 45 46 47 48 |
# File 'lib/pg_eventstore/stream.rb', line 44 def initialize(context:, stream_name:, stream_id:) @context = context @stream_name = stream_name @stream_id = stream_id end |
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
33 34 35 |
# File 'lib/pg_eventstore/stream.rb', line 33 def context @context end |
#stream_id ⇒ Object
Returns the value of attribute stream_id.
39 40 41 |
# File 'lib/pg_eventstore/stream.rb', line 39 def stream_id @stream_id end |
#stream_name ⇒ Object
Returns the value of attribute stream_name.
36 37 38 |
# File 'lib/pg_eventstore/stream.rb', line 36 def stream_name @stream_name end |
Class Method Details
.all_stream ⇒ PgEventstore::Stream
Produces “all” stream instance. “all” stream does not represent any specific stream. Instead, it indicates that a specific command should be performed over any kind of streams if possible
18 19 20 21 22 |
# File 'lib/pg_eventstore/stream.rb', line 18 def all_stream allocate.tap do |stream| stream.instance_variable_set(:@all_stream, true) end end |
.system_stream(name) ⇒ PgEventstore::Stream
26 27 28 |
# File 'lib/pg_eventstore/stream.rb', line 26 def system_stream(name) new(context: name, stream_name: '', stream_id: '') end |
Instance Method Details
#==(other) ⇒ Boolean
96 97 98 99 100 |
# File 'lib/pg_eventstore/stream.rb', line 96 def ==(other) return false unless other.is_a?(Stream) to_hash == other.to_hash end |
#all_stream? ⇒ Boolean
51 52 53 |
# File 'lib/pg_eventstore/stream.rb', line 51 def all_stream? !!@all_stream end |
#deconstruct ⇒ Array Also known as: to_a
62 63 64 |
# File 'lib/pg_eventstore/stream.rb', line 62 def deconstruct [context, stream_name, stream_id] end |
#deconstruct_keys(keys) ⇒ Hash<Symbol => String>
69 70 71 72 73 74 |
# File 'lib/pg_eventstore/stream.rb', line 69 def deconstruct_keys(keys) hash = { context: context, stream_name: stream_name, stream_id: stream_id } return hash unless keys hash.slice(*keys) end |
#eql?(other) ⇒ Boolean
88 89 90 91 92 |
# File 'lib/pg_eventstore/stream.rb', line 88 def eql?(other) return false unless other.is_a?(Stream) hash == other.hash end |
#hash ⇒ Integer
82 83 84 |
# File 'lib/pg_eventstore/stream.rb', line 82 def hash to_hash.hash end |
#system? ⇒ Boolean
Determine whether a stream is reserved by ‘pg_eventstore`. You can’t append events to such streams.
57 58 59 |
# File 'lib/pg_eventstore/stream.rb', line 57 def system? all_stream? || context.start_with?(SYSTEM_STREAM_PREFIX) end |
#to_hash ⇒ Hash
77 78 79 |
# File 'lib/pg_eventstore/stream.rb', line 77 def to_hash deconstruct_keys(nil) end |