Class: Rollgeist::Report

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_location:, accessed_at:, action:, changed_attributes:, model_name:, record_id:, rollback_location:, rolled_back_at:, values:, watchpoint:) ⇒ Report

Returns a new instance of Report.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/rollgeist/report.rb', line 43

def initialize(
  access_location:,
  accessed_at:,
  action:,
  changed_attributes:,
  model_name:,
  record_id:,
  rollback_location:,
  rolled_back_at:,
  values:,
  watchpoint:
)
  @access_location = access_location
  @accessed_at = accessed_at
  @action = action
  @changed_attributes = changed_attributes
  @model_name = model_name
  @record_id = record_id
  @rollback_location = rollback_location
  @rolled_back_at = rolled_back_at
  @values = values
  @watchpoint = watchpoint
  freeze
end

Instance Attribute Details

#access_locationObject (readonly)

Returns the value of attribute access_location.



5
6
7
# File 'lib/rollgeist/report.rb', line 5

def access_location
  @access_location
end

#accessed_atObject (readonly)

Returns the value of attribute accessed_at.



5
6
7
# File 'lib/rollgeist/report.rb', line 5

def accessed_at
  @accessed_at
end

#actionObject (readonly)

Returns the value of attribute action.



5
6
7
# File 'lib/rollgeist/report.rb', line 5

def action
  @action
end

#changed_attributesObject (readonly)

Returns the value of attribute changed_attributes.



5
6
7
# File 'lib/rollgeist/report.rb', line 5

def changed_attributes
  @changed_attributes
end

#model_nameObject (readonly)

Returns the value of attribute model_name.



5
6
7
# File 'lib/rollgeist/report.rb', line 5

def model_name
  @model_name
end

#record_idObject (readonly)

Returns the value of attribute record_id.



5
6
7
# File 'lib/rollgeist/report.rb', line 5

def record_id
  @record_id
end

#rollback_locationObject (readonly)

Returns the value of attribute rollback_location.



5
6
7
# File 'lib/rollgeist/report.rb', line 5

def rollback_location
  @rollback_location
end

#rolled_back_atObject (readonly)

Returns the value of attribute rolled_back_at.



5
6
7
# File 'lib/rollgeist/report.rb', line 5

def rolled_back_at
  @rolled_back_at
end

#valuesObject (readonly)

Returns the value of attribute values.



5
6
7
# File 'lib/rollgeist/report.rb', line 5

def values
  @values
end

#watchpointObject (readonly)

Returns the value of attribute watchpoint.



5
6
7
# File 'lib/rollgeist/report.rb', line 5

def watchpoint
  @watchpoint
end

Class Method Details

.build(record:, mark:, watchpoint:) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rollgeist/report.rb', line 16

def self.build(record:, mark:, watchpoint:)
  changed_attributes = mark.changed_attributes
  values = changed_attributes.to_h do |attribute|
    [attribute, safely_read(record, attribute)]
  end

  new(
    access_location: Rollgeist.capture_location,
    accessed_at: Time.now,
    action: mark.action,
    changed_attributes: changed_attributes,
    model_name: record.class.name || record.class.to_s,
    record_id: record.id,
    rollback_location: mark.rollback_location,
    rolled_back_at: mark.rolled_back_at,
    values: values,
    watchpoint: watchpoint
  )
end

Instance Method Details

#to_hObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/rollgeist/report.rb', line 68

def to_h
  {
    access_location: access_location,
    accessed_at: accessed_at,
    action: action,
    changed_attributes: changed_attributes,
    model_name: model_name,
    record_id: record_id,
    rollback_location: rollback_location,
    rolled_back_at: rolled_back_at,
    values: values,
    watchpoint: watchpoint
  }
end

#to_sObject



83
84
85
# File 'lib/rollgeist/report.rb', line 83

def to_s
  Formatter.new(self).to_s
end