paper_trail 10.3.0 → 10.3.1
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/paper_trail.rb +5 -0
- data/lib/paper_trail/compatibility.rb +51 -0
- data/lib/paper_trail/version_number.rb +1 -1
- metadata +21 -13
- data/lib/generators/paper_trail/install_generator.rb +0 -99
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a08a7c456a492933cc36762913040e14bad8f468fc08889580faf9e86ade7fea
|
4
|
+
data.tar.gz: 19711dc6c6e4a438a0a97819c572df610d52db0f5c9aeba0a39eb1f44f3909c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b39e89605a2b03889976070f0871f9dcd07544b97b6e0105b78035b5fb1ec030c7d5438dc0fe9fb16cccc8e3624cd920d37bd73066f8a4f3892bf356fa088e85
|
7
|
+
data.tar.gz: 56567a718ea4e605d32ffc2b71835b188f6cefab8dd7111b7abcdfc6d9e5b843e8468312ed4dfbc87f74607c1cd4a197ae2c11a9cb44ee2dd16a37a11303e6ad
|
data/lib/paper_trail.rb
CHANGED
@@ -16,6 +16,7 @@ require "active_record"
|
|
16
16
|
|
17
17
|
require "request_store"
|
18
18
|
require "paper_trail/cleaner"
|
19
|
+
require "paper_trail/compatibility"
|
19
20
|
require "paper_trail/config"
|
20
21
|
require "paper_trail/has_paper_trail"
|
21
22
|
require "paper_trail/record_history"
|
@@ -145,3 +146,7 @@ if defined?(::Rails)
|
|
145
146
|
else
|
146
147
|
require "paper_trail/frameworks/active_record"
|
147
148
|
end
|
149
|
+
|
150
|
+
if defined?(::ActiveRecord)
|
151
|
+
::PaperTrail::Compatibility.check_activerecord(::ActiveRecord.gem_version)
|
152
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PaperTrail
|
4
|
+
# Rails does not follow SemVer, makes breaking changes in minor versions.
|
5
|
+
# Breaking changes are expected, and are generally good for the rails
|
6
|
+
# ecosystem. However, they often require dozens of hours to fix, even with the
|
7
|
+
# [help of experts](https://github.com/paper-trail-gem/paper_trail/pull/899).
|
8
|
+
#
|
9
|
+
# It is not safe to assume that a new version of rails will be compatible with
|
10
|
+
# PaperTrail. PT is only compatible with the versions of rails that it is
|
11
|
+
# tested against. See `.travis.yml`.
|
12
|
+
#
|
13
|
+
# However, as of
|
14
|
+
# [#1213](https://github.com/paper-trail-gem/paper_trail/pull/1213) our
|
15
|
+
# gemspec allows installation with newer, incompatible rails versions. We hope
|
16
|
+
# this will make it easier for contributors to work on compatibility with
|
17
|
+
# newer rails versions. Most PT users should avoid incompatible rails
|
18
|
+
# versions.
|
19
|
+
module Compatibility
|
20
|
+
ACTIVERECORD_GTE = ">= 4.2"
|
21
|
+
ACTIVERECORD_LT = "< 6.1"
|
22
|
+
|
23
|
+
E_INCOMPATIBLE_AR = <<-EOS
|
24
|
+
PaperTrail %s is not compatible with ActiveRecord %s. We allow PT
|
25
|
+
contributors to install incompatible versions of ActiveRecord, and this
|
26
|
+
warning can be silenced with an environment variable, but this is a bad
|
27
|
+
idea for normal use. Please install a compatible version of ActiveRecord
|
28
|
+
instead (%s). Please see the discussion in paper_trail/compatibility.rb
|
29
|
+
for details.
|
30
|
+
EOS
|
31
|
+
|
32
|
+
# Normal users need a warning if they accidentally install an incompatible
|
33
|
+
# version of ActiveRecord. Contributors can silence this warning with an
|
34
|
+
# environment variable.
|
35
|
+
def self.check_activerecord(ar_version)
|
36
|
+
raise ::TypeError unless ar_version.instance_of?(::Gem::Version)
|
37
|
+
return if ::ENV["PT_SILENCE_AR_COMPAT_WARNING"].present?
|
38
|
+
req = ::Gem::Requirement.new([ACTIVERECORD_GTE, ACTIVERECORD_LT])
|
39
|
+
unless req.satisfied_by?(ar_version)
|
40
|
+
::Kernel.warn(
|
41
|
+
format(
|
42
|
+
E_INCOMPATIBLE_AR,
|
43
|
+
::PaperTrail.gem_version,
|
44
|
+
ar_version,
|
45
|
+
req
|
46
|
+
)
|
47
|
+
)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
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: 10.3.
|
4
|
+
version: 10.3.1
|
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: 2019-
|
13
|
+
date: 2019-07-31 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
@@ -19,9 +19,6 @@ dependencies:
|
|
19
19
|
- - ">="
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: '4.2'
|
22
|
-
- - "<"
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
version: '6.1'
|
25
22
|
type: :runtime
|
26
23
|
prerelease: false
|
27
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,9 +26,6 @@ dependencies:
|
|
29
26
|
- - ">="
|
30
27
|
- !ruby/object:Gem::Version
|
31
28
|
version: '4.2'
|
32
|
-
- - "<"
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version: '6.1'
|
35
29
|
- !ruby/object:Gem::Dependency
|
36
30
|
name: request_store
|
37
31
|
requirement: !ruby/object:Gem::Requirement
|
@@ -192,28 +186,42 @@ dependencies:
|
|
192
186
|
requirements:
|
193
187
|
- - "~>"
|
194
188
|
- !ruby/object:Gem::Version
|
195
|
-
version: 0.
|
189
|
+
version: 0.71.0
|
190
|
+
type: :development
|
191
|
+
prerelease: false
|
192
|
+
version_requirements: !ruby/object:Gem::Requirement
|
193
|
+
requirements:
|
194
|
+
- - "~>"
|
195
|
+
- !ruby/object:Gem::Version
|
196
|
+
version: 0.71.0
|
197
|
+
- !ruby/object:Gem::Dependency
|
198
|
+
name: rubocop-performance
|
199
|
+
requirement: !ruby/object:Gem::Requirement
|
200
|
+
requirements:
|
201
|
+
- - "~>"
|
202
|
+
- !ruby/object:Gem::Version
|
203
|
+
version: 1.3.0
|
196
204
|
type: :development
|
197
205
|
prerelease: false
|
198
206
|
version_requirements: !ruby/object:Gem::Requirement
|
199
207
|
requirements:
|
200
208
|
- - "~>"
|
201
209
|
- !ruby/object:Gem::Version
|
202
|
-
version:
|
210
|
+
version: 1.3.0
|
203
211
|
- !ruby/object:Gem::Dependency
|
204
212
|
name: rubocop-rspec
|
205
213
|
requirement: !ruby/object:Gem::Requirement
|
206
214
|
requirements:
|
207
215
|
- - "~>"
|
208
216
|
- !ruby/object:Gem::Version
|
209
|
-
version: 1.
|
217
|
+
version: 1.33.0
|
210
218
|
type: :development
|
211
219
|
prerelease: false
|
212
220
|
version_requirements: !ruby/object:Gem::Requirement
|
213
221
|
requirements:
|
214
222
|
- - "~>"
|
215
223
|
- !ruby/object:Gem::Version
|
216
|
-
version: 1.
|
224
|
+
version: 1.33.0
|
217
225
|
- !ruby/object:Gem::Dependency
|
218
226
|
name: sqlite3
|
219
227
|
requirement: !ruby/object:Gem::Requirement
|
@@ -241,7 +249,6 @@ files:
|
|
241
249
|
- lib/generators/paper_trail/install/install_generator.rb
|
242
250
|
- lib/generators/paper_trail/install/templates/add_object_changes_to_versions.rb.erb
|
243
251
|
- lib/generators/paper_trail/install/templates/create_versions.rb.erb
|
244
|
-
- lib/generators/paper_trail/install_generator.rb
|
245
252
|
- lib/generators/paper_trail/migration_generator.rb
|
246
253
|
- lib/generators/paper_trail/update_item_subtype/USAGE
|
247
254
|
- lib/generators/paper_trail/update_item_subtype/templates/update_versions_for_item_subtype.rb.erb
|
@@ -253,6 +260,7 @@ files:
|
|
253
260
|
- lib/paper_trail/attribute_serializers/object_attribute.rb
|
254
261
|
- lib/paper_trail/attribute_serializers/object_changes_attribute.rb
|
255
262
|
- lib/paper_trail/cleaner.rb
|
263
|
+
- lib/paper_trail/compatibility.rb
|
256
264
|
- lib/paper_trail/config.rb
|
257
265
|
- lib/paper_trail/events/base.rb
|
258
266
|
- lib/paper_trail/events/create.rb
|
@@ -1,99 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "rails/generators"
|
4
|
-
require "rails/generators/active_record"
|
5
|
-
|
6
|
-
module PaperTrail
|
7
|
-
# Installs PaperTrail in a rails app.
|
8
|
-
class InstallGenerator < ::Rails::Generators::Base
|
9
|
-
include ::Rails::Generators::Migration
|
10
|
-
|
11
|
-
# Class names of MySQL adapters.
|
12
|
-
# - `MysqlAdapter` - Used by gems: `mysql`, `activerecord-jdbcmysql-adapter`.
|
13
|
-
# - `Mysql2Adapter` - Used by `mysql2` gem.
|
14
|
-
MYSQL_ADAPTERS = [
|
15
|
-
"ActiveRecord::ConnectionAdapters::MysqlAdapter",
|
16
|
-
"ActiveRecord::ConnectionAdapters::Mysql2Adapter"
|
17
|
-
].freeze
|
18
|
-
|
19
|
-
source_root File.expand_path("templates", __dir__)
|
20
|
-
class_option(
|
21
|
-
:with_changes,
|
22
|
-
type: :boolean,
|
23
|
-
default: false,
|
24
|
-
desc: "Store changeset (diff) with each version"
|
25
|
-
)
|
26
|
-
|
27
|
-
desc "Generates (but does not run) a migration to add a versions table."
|
28
|
-
|
29
|
-
def create_migration_file
|
30
|
-
add_paper_trail_migration("create_versions")
|
31
|
-
add_paper_trail_migration("add_object_changes_to_versions") if options.with_changes?
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.next_migration_number(dirname)
|
35
|
-
::ActiveRecord::Generators::Base.next_migration_number(dirname)
|
36
|
-
end
|
37
|
-
|
38
|
-
protected
|
39
|
-
|
40
|
-
def add_paper_trail_migration(template)
|
41
|
-
migration_dir = File.expand_path("db/migrate")
|
42
|
-
if self.class.migration_exists?(migration_dir, template)
|
43
|
-
::Kernel.warn "Migration already exists: #{template}"
|
44
|
-
else
|
45
|
-
migration_template(
|
46
|
-
"#{template}.rb.erb",
|
47
|
-
"db/migrate/#{template}.rb",
|
48
|
-
item_type_options: item_type_options,
|
49
|
-
migration_version: migration_version,
|
50
|
-
versions_table_options: versions_table_options
|
51
|
-
)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
private
|
56
|
-
|
57
|
-
# MySQL 5.6 utf8mb4 limit is 191 chars for keys used in indexes.
|
58
|
-
# See https://github.com/paper-trail-gem/paper_trail/issues/651
|
59
|
-
def item_type_options
|
60
|
-
opt = { null: false }
|
61
|
-
opt[:limit] = 191 if mysql?
|
62
|
-
", #{opt}"
|
63
|
-
end
|
64
|
-
|
65
|
-
def migration_version
|
66
|
-
major = ActiveRecord::VERSION::MAJOR
|
67
|
-
if major >= 5
|
68
|
-
"[#{major}.#{ActiveRecord::VERSION::MINOR}]"
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def mysql?
|
73
|
-
MYSQL_ADAPTERS.include?(ActiveRecord::Base.connection.class.name)
|
74
|
-
end
|
75
|
-
|
76
|
-
# Even modern versions of MySQL still use `latin1` as the default character
|
77
|
-
# encoding. Many users are not aware of this, and run into trouble when they
|
78
|
-
# try to use PaperTrail in apps that otherwise tend to use UTF-8. Postgres, by
|
79
|
-
# comparison, uses UTF-8 except in the unusual case where the OS is configured
|
80
|
-
# with a custom locale.
|
81
|
-
#
|
82
|
-
# - https://dev.mysql.com/doc/refman/5.7/en/charset-applications.html
|
83
|
-
# - http://www.postgresql.org/docs/9.4/static/multibyte.html
|
84
|
-
#
|
85
|
-
# Furthermore, MySQL's original implementation of UTF-8 was flawed, and had
|
86
|
-
# to be fixed later by introducing a new charset, `utf8mb4`.
|
87
|
-
#
|
88
|
-
# - https://mathiasbynens.be/notes/mysql-utf8mb4
|
89
|
-
# - https://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8mb4.html
|
90
|
-
#
|
91
|
-
def versions_table_options
|
92
|
-
if mysql?
|
93
|
-
', { options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci" }'
|
94
|
-
else
|
95
|
-
""
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|