paper_trail 15.1.0 → 16.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/generators/paper_trail/install/templates/create_versions.rb.erb +7 -4
- data/lib/paper_trail/compatibility.rb +1 -1
- data/lib/paper_trail/config.rb +3 -1
- data/lib/paper_trail/frameworks/rails/railtie.rb +5 -1
- data/lib/paper_trail/has_paper_trail.rb +2 -0
- data/lib/paper_trail/model_config.rb +2 -2
- data/lib/paper_trail/record_trail.rb +36 -11
- data/lib/paper_trail/version_number.rb +2 -2
- data/lib/paper_trail.rb +4 -0
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a834abeee917bf2c090c6ef7f6da09437b12aff37c0bcf94f8ff88ca1434203
|
4
|
+
data.tar.gz: 6fdf12293b452fe7dcce563e5f4547d9ae0081399b5cf6885308ea451f29b6ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82fbf4c2ec002d52ee5b4023cbef6a16ef5530e04852a4a3d65fb38b468395016db6230e2f89c199a13549bb9da98a1f53a2b29148a94455bc6470ea7912dcaf
|
7
|
+
data.tar.gz: 9944b2f2e66c9fdc10fe2ecf6f9c560b73da21e49d98504f826158e92faeef5b9cad7a4a1cb1f033217c1f66e230d4c8e2df034c4751298a93df5bf946ef108e
|
@@ -10,11 +10,9 @@ class CreateVersions < ActiveRecord::Migration<%= migration_version %>
|
|
10
10
|
|
11
11
|
def change
|
12
12
|
create_table :versions<%= versions_table_options %><%= version_table_primary_key_type %> do |t|
|
13
|
-
|
14
|
-
t
|
15
|
-
t.string :event, null: false
|
13
|
+
# Consider using bigint type for performance if you are going to store only numeric ids.
|
14
|
+
# t.bigint :whodunnit
|
16
15
|
t.string :whodunnit
|
17
|
-
t.text :object, limit: TEXT_BYTES
|
18
16
|
|
19
17
|
# Known issue in MySQL: fractional second precision
|
20
18
|
# -------------------------------------------------
|
@@ -32,6 +30,11 @@ class CreateVersions < ActiveRecord::Migration<%= migration_version %>
|
|
32
30
|
# MySQL users should use the following line for `created_at`
|
33
31
|
# t.datetime :created_at, limit: 6
|
34
32
|
t.datetime :created_at
|
33
|
+
|
34
|
+
t.<%= item_id_type_options %> :item_id, null: false
|
35
|
+
t.string :item_type<%= item_type_options %>
|
36
|
+
t.string :event, null: false
|
37
|
+
t.text :object, limit: TEXT_BYTES
|
35
38
|
end
|
36
39
|
add_index :versions, %i[item_type item_id]
|
37
40
|
end
|
@@ -18,7 +18,7 @@ module PaperTrail
|
|
18
18
|
# versions.
|
19
19
|
module Compatibility
|
20
20
|
ACTIVERECORD_GTE = ">= 6.1" # enforced in gemspec
|
21
|
-
ACTIVERECORD_LT = "<
|
21
|
+
ACTIVERECORD_LT = "< 8.1" # not enforced in gemspec
|
22
22
|
|
23
23
|
E_INCOMPATIBLE_AR = <<-EOS
|
24
24
|
PaperTrail %s is not compatible with ActiveRecord %s. We allow PT
|
data/lib/paper_trail/config.rb
CHANGED
@@ -14,7 +14,8 @@ module PaperTrail
|
|
14
14
|
:object_changes_adapter,
|
15
15
|
:serializer,
|
16
16
|
:version_limit,
|
17
|
-
:has_paper_trail_defaults
|
17
|
+
:has_paper_trail_defaults,
|
18
|
+
:version_error_behavior
|
18
19
|
)
|
19
20
|
|
20
21
|
def initialize
|
@@ -25,6 +26,7 @@ module PaperTrail
|
|
25
26
|
# Variables which affect all threads, whose access is *not* synchronized.
|
26
27
|
@serializer = PaperTrail::Serializers::YAML
|
27
28
|
@has_paper_trail_defaults = {}
|
29
|
+
@version_error_behavior = :legacy
|
28
30
|
end
|
29
31
|
|
30
32
|
# Indicates whether PaperTrail is on or off. Default: true.
|
@@ -10,7 +10,7 @@ module PaperTrail
|
|
10
10
|
# We specify `before: "load_config_initializers"` to ensure that the PT
|
11
11
|
# initializer happens before "app initializers" (those defined in
|
12
12
|
# the app's `config/initalizers`).
|
13
|
-
initializer "paper_trail", before: "load_config_initializers" do
|
13
|
+
initializer "paper_trail", before: "load_config_initializers" do |app|
|
14
14
|
# `on_load` is a "lazy load hook". It "declares a block that will be
|
15
15
|
# executed when a Rails component is fully loaded". (See
|
16
16
|
# `active_support/lazy_load_hooks.rb`)
|
@@ -25,6 +25,10 @@ module PaperTrail
|
|
25
25
|
ActiveSupport.on_load(:active_record) do
|
26
26
|
require "paper_trail/frameworks/active_record"
|
27
27
|
end
|
28
|
+
|
29
|
+
if Gem::Version.new(::Rails::VERSION::STRING) >= Gem::Version.new("7.1")
|
30
|
+
app.deprecators[:paper_trail] = PaperTrail.deprecator
|
31
|
+
end
|
28
32
|
end
|
29
33
|
end
|
30
34
|
end
|
@@ -68,6 +68,8 @@ module PaperTrail
|
|
68
68
|
#
|
69
69
|
# @api public
|
70
70
|
def has_paper_trail(options = {})
|
71
|
+
raise Error, "has_paper_trail must be called only once" if self < InstanceMethods
|
72
|
+
|
71
73
|
defaults = PaperTrail.config.has_paper_trail_defaults
|
72
74
|
paper_trail.setup(defaults.merge(options))
|
73
75
|
end
|
@@ -156,7 +156,7 @@ module PaperTrail
|
|
156
156
|
# @api private - `version_class_name`
|
157
157
|
@model_class.class_attribute :version_class_name
|
158
158
|
if options[:class_name]
|
159
|
-
|
159
|
+
PaperTrail.deprecator.warn(
|
160
160
|
format(
|
161
161
|
DPR_CLASS_NAME_OPTION,
|
162
162
|
class_name: options[:class_name].inspect
|
@@ -192,7 +192,7 @@ module PaperTrail
|
|
192
192
|
def ensure_versions_option_is_hash(options)
|
193
193
|
unless options[:versions].is_a?(Hash)
|
194
194
|
if options[:versions]
|
195
|
-
|
195
|
+
PaperTrail.deprecator.warn(
|
196
196
|
format(
|
197
197
|
DPR_PASSING_ASSOC_NAME_DIRECTLY_TO_VERSIONS_OPTION,
|
198
198
|
versions_name: options[:versions].inspect
|
@@ -64,6 +64,8 @@ module PaperTrail
|
|
64
64
|
# of versions_assoc.build?, the association cache is unaware. So, we
|
65
65
|
# invalidate the `versions` association cache with `reset`.
|
66
66
|
versions.reset
|
67
|
+
rescue StandardError => e
|
68
|
+
handle_version_errors e, version, :create
|
67
69
|
end
|
68
70
|
end
|
69
71
|
|
@@ -81,12 +83,13 @@ module PaperTrail
|
|
81
83
|
# `data_for_destroy` but PT-AT still does.
|
82
84
|
data = event.data.merge(data_for_destroy)
|
83
85
|
|
84
|
-
version = @record.class.paper_trail.version_class.
|
85
|
-
|
86
|
-
|
87
|
-
else
|
86
|
+
version = @record.class.paper_trail.version_class.new(data)
|
87
|
+
begin
|
88
|
+
version.save!
|
88
89
|
assign_and_reset_version_association(version)
|
89
90
|
version
|
91
|
+
rescue StandardError => e
|
92
|
+
handle_version_errors e, version, :destroy
|
90
93
|
end
|
91
94
|
end
|
92
95
|
|
@@ -108,14 +111,15 @@ module PaperTrail
|
|
108
111
|
)
|
109
112
|
return unless version
|
110
113
|
|
111
|
-
|
114
|
+
begin
|
115
|
+
version.save!
|
112
116
|
# Because the version object was created using version_class.new instead
|
113
117
|
# of versions_assoc.build?, the association cache is unaware. So, we
|
114
118
|
# invalidate the `versions` association cache with `reset`.
|
115
119
|
versions.reset
|
116
120
|
version
|
117
|
-
|
118
|
-
|
121
|
+
rescue StandardError => e
|
122
|
+
handle_version_errors e, version, :update
|
119
123
|
end
|
120
124
|
end
|
121
125
|
|
@@ -286,6 +290,26 @@ module PaperTrail
|
|
286
290
|
)
|
287
291
|
end
|
288
292
|
|
293
|
+
# Centralized handler for version errors
|
294
|
+
# @api private
|
295
|
+
def handle_version_errors(e, version, action)
|
296
|
+
case PaperTrail.config.version_error_behavior
|
297
|
+
when :legacy
|
298
|
+
# legacy behavior was to raise on create and log on update/delete
|
299
|
+
if action == :create
|
300
|
+
raise e
|
301
|
+
else
|
302
|
+
log_version_errors(version, action)
|
303
|
+
end
|
304
|
+
when :log
|
305
|
+
log_version_errors(version, action)
|
306
|
+
when :exception
|
307
|
+
raise e
|
308
|
+
when :silent
|
309
|
+
# noop
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
289
313
|
# @api private
|
290
314
|
# @return - The created version object, so that plugins can use it, e.g.
|
291
315
|
# paper_trail-association_tracking
|
@@ -298,11 +322,12 @@ module PaperTrail
|
|
298
322
|
data.merge!(data_for_update_columns)
|
299
323
|
|
300
324
|
versions_assoc = @record.send(@record.class.versions_association_name)
|
301
|
-
version = versions_assoc.
|
302
|
-
|
303
|
-
|
304
|
-
else
|
325
|
+
version = versions_assoc.new(data)
|
326
|
+
begin
|
327
|
+
version.save!
|
305
328
|
version
|
329
|
+
rescue StandardError => e
|
330
|
+
handle_version_errors e, version, :update
|
306
331
|
end
|
307
332
|
end
|
308
333
|
|
@@ -7,8 +7,8 @@ module PaperTrail
|
|
7
7
|
# because of this confusion, but it's not worth the breaking change.
|
8
8
|
# People are encouraged to use `PaperTrail.gem_version` instead.
|
9
9
|
module VERSION
|
10
|
-
MAJOR =
|
11
|
-
MINOR =
|
10
|
+
MAJOR = 16
|
11
|
+
MINOR = 0
|
12
12
|
TINY = 0
|
13
13
|
|
14
14
|
# Set PRE to nil unless it's a pre-release (beta, rc, etc.)
|
data/lib/paper_trail.rb
CHANGED
@@ -118,6 +118,10 @@ module PaperTrail
|
|
118
118
|
def active_record_gte_7_0?
|
119
119
|
@active_record_gte_7_0 ||= ::ActiveRecord.gem_version >= ::Gem::Version.new("7.0.0")
|
120
120
|
end
|
121
|
+
|
122
|
+
def deprecator
|
123
|
+
@deprecator ||= ActiveSupport::Deprecation.new("16.0", "PaperTrail")
|
124
|
+
end
|
121
125
|
end
|
122
126
|
end
|
123
127
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paper_trail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 16.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Stewart
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2024-11-08 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
@@ -46,14 +46,14 @@ dependencies:
|
|
46
46
|
requirements:
|
47
47
|
- - "~>"
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: 2.
|
49
|
+
version: '2.5'
|
50
50
|
type: :development
|
51
51
|
prerelease: false
|
52
52
|
version_requirements: !ruby/object:Gem::Requirement
|
53
53
|
requirements:
|
54
54
|
- - "~>"
|
55
55
|
- !ruby/object:Gem::Version
|
56
|
-
version: 2.
|
56
|
+
version: '2.5'
|
57
57
|
- !ruby/object:Gem::Dependency
|
58
58
|
name: byebug
|
59
59
|
requirement: !ruby/object:Gem::Requirement
|
@@ -351,7 +351,8 @@ files:
|
|
351
351
|
homepage: https://github.com/paper-trail-gem/paper_trail
|
352
352
|
licenses:
|
353
353
|
- MIT
|
354
|
-
metadata:
|
354
|
+
metadata:
|
355
|
+
changelog_uri: https://github.com/paper-trail-gem/paper_trail/blob/master/CHANGELOG.md
|
355
356
|
post_install_message:
|
356
357
|
rdoc_options: []
|
357
358
|
require_paths:
|
@@ -367,7 +368,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
367
368
|
- !ruby/object:Gem::Version
|
368
369
|
version: 1.3.6
|
369
370
|
requirements: []
|
370
|
-
rubygems_version: 3.
|
371
|
+
rubygems_version: 3.4.19
|
371
372
|
signing_key:
|
372
373
|
specification_version: 4
|
373
374
|
summary: Track changes to your models.
|