module Twobook::Corrections
Public Class Methods
make_deletion(event, accounts, history, happened_at: Time.current)
click to toggle source
# 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)
click to toggle source
# 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