Class: DurableFlow::Live::Change

Inherits:
Struct
  • Object
show all
Defined in:
lib/durable_flow/live.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#occurred_atObject

Returns the value of attribute occurred_at

Returns:

  • (Object)

    the current value of occurred_at



5
6
7
# File 'lib/durable_flow/live.rb', line 5

def occurred_at
  @occurred_at
end

#recordObject

Returns the value of attribute record

Returns:

  • (Object)

    the current value of record



5
6
7
# File 'lib/durable_flow/live.rb', line 5

def record
  @record
end

#record_classObject

Returns the value of attribute record_class

Returns:

  • (Object)

    the current value of record_class



5
6
7
# File 'lib/durable_flow/live.rb', line 5

def record_class
  @record_class
end

#record_idObject

Returns the value of attribute record_id

Returns:

  • (Object)

    the current value of record_id



5
6
7
# File 'lib/durable_flow/live.rb', line 5

def record_id
  @record_id
end

#run_idObject

Returns the value of attribute run_id

Returns:

  • (Object)

    the current value of run_id



5
6
7
# File 'lib/durable_flow/live.rb', line 5

def run_id
  @run_id
end

#snapshotObject

Returns the value of attribute snapshot

Returns:

  • (Object)

    the current value of snapshot



5
6
7
# File 'lib/durable_flow/live.rb', line 5

def snapshot
  @snapshot
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



5
6
7
# File 'lib/durable_flow/live.rb', line 5

def type
  @type
end

#workflow_classObject

Returns the value of attribute workflow_class

Returns:

  • (Object)

    the current value of workflow_class



5
6
7
# File 'lib/durable_flow/live.rb', line 5

def workflow_class
  @workflow_class
end

Class Method Details

.from_record(record, action:) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/durable_flow/live.rb', line 16

def self.from_record(record, action:)
  workflow_run = workflow_run_for(record)

  new(
    type: "#{record.model_name.element}.#{action}",
    run_id: workflow_run&.run_id,
    workflow_class: workflow_run&.workflow_class,
    record_class: record.class.name,
    record_id: record.id,
    record: record,
    snapshot: record.live_snapshot,
    occurred_at: Time.current,
  )
end

Instance Method Details

#payloadObject



31
32
33
34
35
36
37
38
39
40
# File 'lib/durable_flow/live.rb', line 31

def payload
  snapshot.merge(
    type: type,
    run_id: run_id,
    workflow_class: workflow_class,
    record_class: record_class,
    record_id: record_id,
    occurred_at: occurred_at,
  ).compact
end