Class: Igniter::Store::ChangeEvent

Inherits:
Struct
  • Object
show all
Defined in:
lib/igniter/store/change_event.rb

Overview

Immutable value object emitted after each committed fact write.

Carries a compact reference to the committed fact (fact_id, store, key, timestamps, causation) plus a monotonic cursor sequence assigned by the emitting ChangefeedBuffer.

The fact field carries the full Fact object for transports (e.g. TCP push) that need the complete payload on delivery. It is not included in to_h to keep wire representations compact.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#causationObject

Returns the value of attribute causation

Returns:

  • (Object)

    the current value of causation



16
17
18
# File 'lib/igniter/store/change_event.rb', line 16

def causation
  @causation
end

#cursorObject

Returns the value of attribute cursor

Returns:

  • (Object)

    the current value of cursor



16
17
18
# File 'lib/igniter/store/change_event.rb', line 16

def cursor
  @cursor
end

#emitted_atObject

Returns the value of attribute emitted_at

Returns:

  • (Object)

    the current value of emitted_at



16
17
18
# File 'lib/igniter/store/change_event.rb', line 16

def emitted_at
  @emitted_at
end

#factObject

Returns the value of attribute fact

Returns:

  • (Object)

    the current value of fact



16
17
18
# File 'lib/igniter/store/change_event.rb', line 16

def fact
  @fact
end

#fact_idObject

Returns the value of attribute fact_id

Returns:

  • (Object)

    the current value of fact_id



16
17
18
# File 'lib/igniter/store/change_event.rb', line 16

def fact_id
  @fact_id
end

#idObject

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



16
17
18
# File 'lib/igniter/store/change_event.rb', line 16

def id
  @id
end

#keyObject

Returns the value of attribute key

Returns:

  • (Object)

    the current value of key



16
17
18
# File 'lib/igniter/store/change_event.rb', line 16

def key
  @key
end

#producerObject

Returns the value of attribute producer

Returns:

  • (Object)

    the current value of producer



16
17
18
# File 'lib/igniter/store/change_event.rb', line 16

def producer
  @producer
end

#schema_versionObject

Returns the value of attribute schema_version

Returns:

  • (Object)

    the current value of schema_version



16
17
18
# File 'lib/igniter/store/change_event.rb', line 16

def schema_version
  @schema_version
end

#storeObject

Returns the value of attribute store

Returns:

  • (Object)

    the current value of store



16
17
18
# File 'lib/igniter/store/change_event.rb', line 16

def store
  @store
end

#transaction_timeObject

Returns the value of attribute transaction_time

Returns:

  • (Object)

    the current value of transaction_time



16
17
18
# File 'lib/igniter/store/change_event.rb', line 16

def transaction_time
  @transaction_time
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



16
17
18
# File 'lib/igniter/store/change_event.rb', line 16

def type
  @type
end

Class Method Details

.from_fact(fact, sequence:) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/igniter/store/change_event.rb', line 31

def self.from_fact(fact, sequence:)
  new(
    schema_version:   1,
    id:               "change_#{SecureRandom.uuid}",
    type:             :fact_committed,
    store:            fact.store,
    key:              fact.key,
    fact_id:          fact.id,
    transaction_time: fact.transaction_time,
    emitted_at:       Process.clock_gettime(Process::CLOCK_REALTIME),
    producer:         fact.producer,
    causation:        fact.causation,
    cursor:           { sequence: sequence }.freeze,
    fact:             fact
  ).freeze
end

Instance Method Details

#to_hObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/igniter/store/change_event.rb', line 48

def to_h
  {
    schema_version:   schema_version,
    id:               id,
    type:             type,
    store:            store,
    key:              key,
    fact_id:          fact_id,
    transaction_time: transaction_time,
    emitted_at:       emitted_at,
    producer:         producer,
    causation:        causation,
    cursor:           cursor
  }
end