File: callback_modifier.rb

package info (click to toggle)
ruby-paper-trail 12.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,200 kB
  • sloc: ruby: 6,743; makefile: 6
file content (49 lines) | stat: -rw-r--r-- 925 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# frozen_string_literal: true

class CallbackModifier < ActiveRecord::Base
  has_paper_trail on: []

  def test_destroy
    transaction do
      run_callbacks(:destroy) do
        self.deleted = true
        save!
      end
    end
  end

  def flagged_deleted?
    deleted?
  end
end

class BeforeDestroyModifier < CallbackModifier
  has_paper_trail on: []
  paper_trail.on_destroy :before
end

unless ActiveRecord::Base.belongs_to_required_by_default
  class AfterDestroyModifier < CallbackModifier
    has_paper_trail on: []
    paper_trail.on_destroy :after
  end
end

class NoArgDestroyModifier < CallbackModifier
  has_paper_trail on: []
  paper_trail.on_destroy
end

class UpdateModifier < CallbackModifier
  has_paper_trail on: []
  paper_trail.on_update
end

class CreateModifier < CallbackModifier
  has_paper_trail on: []
  paper_trail.on_create
end

class DefaultModifier < CallbackModifier
  has_paper_trail
end