Class: PgEventstore::Event

Inherits:
Object
  • Object
show all
Includes:
PgEventstore::Extensions::OptionsExtension
Defined in:
lib/pg_eventstore/event.rb,
sig/pg_eventstore/event.rbs

Constant Summary collapse

'$>'
SYSTEM_SYMBOL =

Returns:

  • (String)
"\u2592"
MARKERS_METADATA_KEY =

Returns:

  • (String)
"#{SYSTEM_SYMBOL}m".freeze
PRIMARY_TABLE_NAME =

Returns:

  • (String)
'events'
NON_EXISTING_EVENT_REVISION =

Returns:

  • (Integer)
-1
SYSTEM_KEY_PREFIX =

Returns:

  • (String)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PgEventstore::Extensions::OptionsExtension

included

Constructor Details

#initializeEvent

Returns a new instance of Event.

Parameters:

  • options (Object)


18
# File 'sig/pg_eventstore/event.rbs', line 18

def initialize: (**untyped options) -> void

Instance Attribute Details

#causation_idString?

Returns UUIDv7.

Parameters:

  • value (String, nil)

Returns:

  • (String, nil)

    UUIDv7



68
# File 'lib/pg_eventstore/event.rb', line 68

attribute(:causation_id)

#caused_byPgEventstore::Event?

Parameters:

Returns:



62
# File 'lib/pg_eventstore/event.rb', line 62

attribute(:caused_by)

#correlation_idString?

Returns UUIDv7.

Parameters:

  • value (String, nil)

Returns:

  • (String, nil)

    UUIDv7



65
# File 'lib/pg_eventstore/event.rb', line 65

attribute(:correlation_id)

#created_atTime?

Returns a timestamp an event was created at.

Parameters:

  • value (Time, nil)

Returns:

  • (Time, nil)

    a timestamp an event was created at



59
# File 'lib/pg_eventstore/event.rb', line 59

attribute(:created_at)

#dataHash

Returns event's data.

Parameters:

  • value (::Hash[untyped, untyped])

Returns:

  • (Hash)

    event's data



35
# File 'lib/pg_eventstore/event.rb', line 35

attribute(:data) { {} }

#feature_markersArray<FeatureMarker>

Returns feature-specific markers that can't be put under #markers.

Parameters:

Returns:

  • (Array<FeatureMarker>)

    feature-specific markers that can't be put under #markers



41
# File 'lib/pg_eventstore/event.rb', line 41

attribute(:feature_markers) { [] }

#global_positionInteger

Returns event's position in "all" stream.

Parameters:

  • value (Integer, nil)

Returns:

  • (Integer)

    event's position in "all" stream



26
# File 'lib/pg_eventstore/event.rb', line 26

attribute(:global_position)

#idString

Returns UUIDv7.

Parameters:

  • value (String, nil)

Returns:

  • (String)

    UUIDv7



20
# File 'lib/pg_eventstore/event.rb', line 20

attribute(:id) { SecureRandom.uuid_v7 }

Returns when resolve_link_tos: true option is provided during the read of events and event is a link event - this attribute will be pointing on that link.

Parameters:

Returns:

  • (PgEventstore::Event, nil)

    when resolve_link_tos: true option is provided during the read of events and event is a link event - this attribute will be pointing on that link



56
# File 'lib/pg_eventstore/event.rb', line 56

attribute(:link)

Returns global_position of an event the current event points to. If it is not nil, then the current event is a link.

Parameters:

  • value (Integer, nil)

Returns:

  • (Integer, nil)

    global_position of an event the current event points to. If it is not nil, then the current event is a link



48
# File 'lib/pg_eventstore/event.rb', line 48

attribute(:link_global_position)

Returns a partition id of an event the link event points to. It is used to load original event when resolve_link_tos: true option is provided when reading events.

Parameters:

  • value (Integer, nil)

Returns:

  • (Integer, nil)

    a partition id of an event the link event points to. It is used to load original event when resolve_link_tos: true option is provided when reading events.



52
# File 'lib/pg_eventstore/event.rb', line 52

attribute(:link_partition_id)

#markersArray<String>

Returns event markers.

Parameters:

  • value (::Array[String])

Returns:

  • (Array<String>)

    event markers



38
# File 'lib/pg_eventstore/event.rb', line 38

attribute(:markers) { [] }

#metadataHash

Returns event's metadata.

Parameters:

  • value (::Hash[untyped, untyped])

Returns:

  • (Hash)

    event's metadata



44
# File 'lib/pg_eventstore/event.rb', line 44

attribute(:metadata) { {} }

#streamPgEventstore::Stream?

Returns event's stream.

Parameters:

Returns:



29
# File 'lib/pg_eventstore/event.rb', line 29

attribute(:stream)

#stream_revisionInteger

Returns a revision of an event inside event's stream.

Parameters:

  • value (Integer, nil)

Returns:

  • (Integer)

    a revision of an event inside event's stream



32
# File 'lib/pg_eventstore/event.rb', line 32

attribute(:stream_revision)

#typeString

Returns event type.

Parameters:

  • value (String)

Returns:

  • (String)

    event type



23
# File 'lib/pg_eventstore/event.rb', line 23

attribute(:type) { self.class.name }

Instance Method Details

#==(other) ⇒ Boolean Also known as: eql?

Implements comparison of PgEventstore::Event-s. Two events matches if all of their attributes matches

Parameters:

Returns:

  • (Boolean)


73
74
75
76
77
# File 'lib/pg_eventstore/event.rb', line 73

def ==(other)
  return false unless other.is_a?(PgEventstore::Event)

  attributes_hash.except(:link) == other.attributes_hash.except(:link)
end

#dupself

Returns:

  • (self)


98
99
100
# File 'lib/pg_eventstore/event.rb', line 98

def dup
  self.class.new(**Utils.deep_dup(options_hash))
end

#hashInteger

Returns:

  • (Integer)


87
88
89
# File 'lib/pg_eventstore/event.rb', line 87

def hash
  attributes_hash.except(:link).hash
end

#init_default_valuesvoid

This method returns an undefined value.

Parameters:

  • options (::Hash[untyped, untyped])


28
# File 'sig/pg_eventstore/event.rbs', line 28

def init_default_values: (::Hash[untyped, untyped] options) -> void

#link?Boolean

Detect whether an event is a link event

Returns:

  • (Boolean)


82
83
84
# File 'lib/pg_eventstore/event.rb', line 82

def link?
  !link_global_position.nil?
end

#options_hash::Hash[untyped, untyped]

Returns:

  • (::Hash[untyped, untyped])


20
# File 'sig/pg_eventstore/event.rbs', line 20

def options_hash: () -> ::Hash[untyped, untyped]

#readonly!Boolean

Parameters:

  • opt_name (Symbol)

Returns:

  • (Boolean)


22
# File 'sig/pg_eventstore/event.rbs', line 22

def readonly!: (Symbol opt_name) -> bool

#readonly?Boolean

Parameters:

  • opt_name (Symbol)

Returns:

  • (Boolean)


24
# File 'sig/pg_eventstore/event.rbs', line 24

def readonly?: (Symbol opt_name) -> bool

#readonly_errorvoid

This method returns an undefined value.

Parameters:

  • opt_name (Symbol)


26
# File 'sig/pg_eventstore/event.rbs', line 26

def readonly_error: (Symbol opt_name) -> void

#system?Boolean

Detect whether an event is a system event

Returns:

  • (Boolean)


93
94
95
# File 'lib/pg_eventstore/event.rb', line 93

def system?
  type.start_with?('$')
end