Module: Twobook::Corrections
- Defined in:
- lib/twobook/corrections.rb
Defined Under Namespace
Classes: Correction, CorrectionBuffer, CorrectionMade, SimulatedDifferenceAdjustment
Class Method Summary
collapse
Class Method Details
.make_deletion(event, accounts, history, happened_at: Time.current) ⇒ Object
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/twobook/corrections.rb', line 3
def self.make_deletion(event, accounts, history, happened_at: Time.current)
correct_history = history - [event]
correct_history.reject! { |historical_event| historical_event < event }
snapshots = accounts.map do |a|
Serialization.serialize_account(a, before_event: event, allow_empty: false)
end.compact
CorrectionMade.new(
account_snapshots: snapshots,
corrected_events: correct_history.map { |e| Serialization.serialize_event(e) },
correction_explanation: { event_uuid: event.uuid, type: 'deletion' },
happened_at: happened_at,
)
end
|
.make_edit(edited_event, accounts, history, happened_at: Time.current) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/twobook/corrections.rb', line 19
def self.make_edit(edited_event, accounts, history, happened_at: Time.current)
index = history.index(edited_event)
correct_history = history.deep_dup
correct_history[index] = edited_event
correct_history.reject! { |historical_event| historical_event < edited_event }
snapshots = accounts.map do |a|
Serialization.serialize_account(a, before_event: edited_event, allow_empty: false)
end.compact
CorrectionMade.new(
account_snapshots: snapshots,
corrected_events: correct_history.map { |e| Serialization.serialize_event(e) },
correction_explanation: { event_uuid: edited_event.uuid, type: 'edit', new_parameters: edited_event.data },
happened_at: happened_at,
)
end
|