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
  "    Rollgeist::GhostRecordAccess\n\n    \#{record_label} \#{ACCESS_DESCRIPTIONS.fetch(report.watchpoint)} after its \#{ACTION_DESCRIPTIONS.fetch(report.action)} was rolled back.\n\n    The in-memory object still carries:\n    \#{formatted_values}\n\n    Rolled back at:\n      \#{report.rollback_location || \"(location unavailable)\"}  (\#{formatted_age} ago)\n\n    Accessed at:\n      \#{report.access_location || \"(location unavailable)\"}\n\n    Call `record.reload` before using this object,\n    or move the usage inside the transaction.\n  MESSAGE\nend\n".chomp