Class: Rollgeist::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/rollgeist/formatter.rb

Constant Summary collapse

ACCESS_DESCRIPTIONS =
{
  global_id: "was converted to a GlobalID",
  resave: "was saved or destroyed again",
  serialization: "was serialized"
}.freeze
ACTION_DESCRIPTIONS =
{
  create: "creation",
  destroy: "destruction",
  update: "update"
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(report) ⇒ Formatter

Returns a new instance of Formatter.



16
17
18
# File 'lib/rollgeist/formatter.rb', line 16

def initialize(report)
  @report = report
end

Instance Method Details

#to_sObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rollgeist/formatter.rb', line 20

def to_s
  <<~MESSAGE.chomp
    Rollgeist::GhostRecordAccess

    #{record_label} #{ACCESS_DESCRIPTIONS.fetch(report.watchpoint)} after its #{ACTION_DESCRIPTIONS.fetch(report.action)} was rolled back.

    The in-memory object still carries:
    #{formatted_values}

    Rolled back at:
      #{report.rollback_location || "(location unavailable)"}  (#{formatted_age} ago)

    Accessed at:
      #{report.access_location || "(location unavailable)"}

    Call `record.reload` before using this object,
    or move the usage inside the transaction.
  MESSAGE
end