Class: PgEventstore::Stream

Inherits:
Object
  • Object
show all
Defined in:
lib/pg_eventstore/stream.rb,
sig/pg_eventstore/stream.rbs

Constant Summary collapse

NON_EXISTING_STREAM_REVISION =

Returns:

  • (Integer)
-1
# @return [Array<String>]
KNOWN_SYSTEM_STREAMS =

Returns:

  • (Array<String>)
%w[].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context:, stream_name:, stream_id:, stream_revision: nil, starting_position: nil) ⇒ Stream

Returns a new instance of Stream.

Parameters:

  • context (String)
  • stream_name (String)
  • stream_id (String)
  • stream_revision (Integer, nil) (defaults to: nil)
  • starting_position (Integer, nil) (defaults to: nil)


44
45
46
47
48
49
50
# File 'lib/pg_eventstore/stream.rb', line 44

def initialize(context:, stream_name:, stream_id:, stream_revision: nil, starting_position: nil)
  @context = context
  @stream_name = stream_name
  @stream_id = stream_id
  @stream_revision = stream_revision
  @starting_position = starting_position
end

Instance Attribute Details

#contextString

Returns the value of attribute context.

Returns:

  • (String)


25
26
27
# File 'lib/pg_eventstore/stream.rb', line 25

def context
  @context
end

#starting_positionInteger?

Returns the value of attribute starting_position.

Returns:

  • (Integer, nil)


37
38
39
# File 'lib/pg_eventstore/stream.rb', line 37

def starting_position
  @starting_position
end

#stream_idString

Returns the value of attribute stream_id.

Returns:

  • (String)


31
32
33
# File 'lib/pg_eventstore/stream.rb', line 31

def stream_id
  @stream_id
end

#stream_nameString

Returns the value of attribute stream_name.

Returns:

  • (String)


28
29
30
# File 'lib/pg_eventstore/stream.rb', line 28

def stream_name
  @stream_name
end

#stream_revisionInteger?

Returns the value of attribute stream_revision.

Returns:

  • (Integer, nil)


34
35
36
# File 'lib/pg_eventstore/stream.rb', line 34

def stream_revision
  @stream_revision
end

Class Method Details

.all_streamPgEventstore::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



16
17
18
19
20
# File 'lib/pg_eventstore/stream.rb', line 16

def all_stream
  allocate.tap do |stream|
    stream.instance_variable_set(:@all_stream, true)
  end
end

.system_streamStream

Parameters:

  • (String)

Returns:



8
# File 'sig/pg_eventstore/stream.rbs', line 8

def self.system_stream: (String) -> Stream

Instance Method Details

#==(other) ⇒ Boolean

Parameters:

  • other (Object)
  • other_stream (Object)

Returns:

  • (Boolean)


93
94
95
96
97
# File 'lib/pg_eventstore/stream.rb', line 93

def ==(other)
  return false unless other.is_a?(Stream)

  to_hash == other.to_hash
end

#all_stream?Boolean Also known as: system?

Returns:

  • (Boolean)


53
54
55
# File 'lib/pg_eventstore/stream.rb', line 53

def all_stream?
  !!@all_stream
end

#deconstructArray Also known as: to_a

Returns:

  • (Array)


59
60
61
# File 'lib/pg_eventstore/stream.rb', line 59

def deconstruct
  [context, stream_name, stream_id]
end

#deconstruct_keys(keys) ⇒ Hash<Symbol => String>

Parameters:

  • keys (Array<Symbol>, nil)

Returns:

  • (Hash<Symbol => String>)


66
67
68
69
70
71
# File 'lib/pg_eventstore/stream.rb', line 66

def deconstruct_keys(keys)
  hash = { context:, stream_name:, stream_id: }
  return hash unless keys

  hash.slice(*keys)
end

#eql?(other) ⇒ Boolean

Parameters:

  • other (Object)
  • another (Object)

Returns:

  • (Boolean)


85
86
87
88
89
# File 'lib/pg_eventstore/stream.rb', line 85

def eql?(other)
  return false unless other.is_a?(Stream)

  hash == other.hash
end

#hashInteger

Returns:

  • (Integer)


79
80
81
# File 'lib/pg_eventstore/stream.rb', line 79

def hash
  to_hash.hash
end

#to_hashHash

Returns:

  • (Hash)


74
75
76
# File 'lib/pg_eventstore/stream.rb', line 74

def to_hash
  deconstruct_keys(nil)
end