paper_trail 8.1.0 → 8.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/paper_trail.rb +1 -1
- data/lib/paper_trail/attribute_serializers/attribute_serializer_factory.rb +25 -0
- data/lib/paper_trail/attribute_serializers/cast_attribute_serializer.rb +4 -2
- data/lib/paper_trail/frameworks/rails/controller.rb +6 -3
- data/lib/paper_trail/type_serializers/postgres_array_serializer.rb +47 -0
- data/lib/paper_trail/version_number.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 389976a20a0d3d80ff31006b9ad5f58e8c66b2678d96eb6bdf25d461d28dc182
|
4
|
+
data.tar.gz: 0d7a51d9715a65cd7a0f509d9db888a8b6b01514c9f6a56bd13940fced350361
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26239968c3d59c0a745d66990d053f2ca9a03bce8dfd31bbd4d811abcb05e58cad0fa1cf7d4ac7882325861e07edacb295b24c34ae29f7b880d23bff9ba718bc
|
7
|
+
data.tar.gz: d6c8b8104f81dfd31ecb64cc4ec936fb22d3b079ac686628f36e3c770c6f768d1953a47c195f11587ffd9e2afc840616364bf89f5893ea93e6dbd1cdf6064697
|
data/lib/paper_trail.rb
CHANGED
@@ -22,7 +22,7 @@ module PaperTrail
|
|
22
22
|
EOS
|
23
23
|
E_TIMESTAMP_FIELD_CONFIG = <<-EOS.squish.freeze
|
24
24
|
PaperTrail.timestamp_field= has been removed, without replacement. It is no
|
25
|
-
longer configurable. The timestamp
|
25
|
+
longer configurable. The timestamp column in the versions table must now be
|
26
26
|
named created_at.
|
27
27
|
EOS
|
28
28
|
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "paper_trail/type_serializers/postgres_array_serializer"
|
2
|
+
|
3
|
+
module PaperTrail
|
4
|
+
module AttributeSerializers
|
5
|
+
# Values returned by some Active Record serializers are
|
6
|
+
# not suited for writing JSON to a text column. This factory
|
7
|
+
# replaces certain default Active Record serializers
|
8
|
+
# with custom PaperTrail ones.
|
9
|
+
module AttributeSerializerFactory
|
10
|
+
AR_PG_ARRAY_CLASS = "ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array".freeze
|
11
|
+
|
12
|
+
def self.for(klass, attr)
|
13
|
+
active_record_serializer = klass.type_for_attribute(attr)
|
14
|
+
if active_record_serializer.class.name == AR_PG_ARRAY_CLASS
|
15
|
+
TypeSerializers::PostgresArraySerializer.new(
|
16
|
+
active_record_serializer.subtype,
|
17
|
+
active_record_serializer.delimiter
|
18
|
+
)
|
19
|
+
else
|
20
|
+
active_record_serializer
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require "paper_trail/attribute_serializers/attribute_serializer_factory"
|
2
|
+
|
1
3
|
module PaperTrail
|
2
4
|
# :nodoc:
|
3
5
|
module AttributeSerializers
|
@@ -32,7 +34,7 @@ module PaperTrail
|
|
32
34
|
# This implementation uses AR 5's `serialize` and `deserialize`.
|
33
35
|
class CastAttributeSerializer
|
34
36
|
def serialize(attr, val)
|
35
|
-
@klass
|
37
|
+
AttributeSerializerFactory.for(@klass, attr).serialize(val)
|
36
38
|
end
|
37
39
|
|
38
40
|
def deserialize(attr, val)
|
@@ -40,7 +42,7 @@ module PaperTrail
|
|
40
42
|
# Because PT 4 used to save the string version of enums to `object_changes`
|
41
43
|
val
|
42
44
|
else
|
43
|
-
@klass
|
45
|
+
AttributeSerializerFactory.for(@klass, attr).deserialize(val)
|
44
46
|
end
|
45
47
|
end
|
46
48
|
end
|
@@ -66,14 +66,17 @@ module PaperTrail
|
|
66
66
|
|
67
67
|
# Tells PaperTrail who is responsible for any changes that occur.
|
68
68
|
def set_paper_trail_whodunnit
|
69
|
-
|
70
|
-
|
69
|
+
if ::PaperTrail.enabled_for_controller?
|
70
|
+
::PaperTrail.whodunnit = user_for_paper_trail
|
71
|
+
end
|
71
72
|
end
|
72
73
|
|
73
74
|
# Tells PaperTrail any information from the controller you want to store
|
74
75
|
# alongside any changes that occur.
|
75
76
|
def set_paper_trail_controller_info
|
76
|
-
|
77
|
+
if ::PaperTrail.enabled_for_controller?
|
78
|
+
::PaperTrail.controller_info = info_for_paper_trail
|
79
|
+
end
|
77
80
|
end
|
78
81
|
|
79
82
|
# We have removed this warning. We no longer add it as a callback.
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module PaperTrail
|
2
|
+
module TypeSerializers
|
3
|
+
# Provides an alternative method of serialization
|
4
|
+
# and deserialization of PostgreSQL array columns.
|
5
|
+
class PostgresArraySerializer
|
6
|
+
def initialize(subtype, delimiter)
|
7
|
+
@subtype = subtype
|
8
|
+
@delimiter = delimiter
|
9
|
+
end
|
10
|
+
|
11
|
+
def serialize(array)
|
12
|
+
return serialize_with_ar(array) if active_record_pre_502?
|
13
|
+
array
|
14
|
+
end
|
15
|
+
|
16
|
+
def deserialize(array)
|
17
|
+
return deserialize_with_ar(array) if active_record_pre_502?
|
18
|
+
|
19
|
+
case array
|
20
|
+
# Needed for legacy reasons. If serialized array is a string
|
21
|
+
# then it was serialized with Rails < 5.0.2.
|
22
|
+
when ::String then deserialize_with_ar(array)
|
23
|
+
else array
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def active_record_pre_502?
|
30
|
+
::ActiveRecord::VERSION::MAJOR < 5 ||
|
31
|
+
(::ActiveRecord::VERSION::MINOR.zero? && ::ActiveRecord::VERSION::TINY < 2)
|
32
|
+
end
|
33
|
+
|
34
|
+
def serialize_with_ar(array)
|
35
|
+
ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array.
|
36
|
+
new(@subtype, @delimiter).
|
37
|
+
serialize(array)
|
38
|
+
end
|
39
|
+
|
40
|
+
def deserialize_with_ar(array)
|
41
|
+
ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array.
|
42
|
+
new(@subtype, @delimiter).
|
43
|
+
deserialize(array)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
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: 8.1.
|
4
|
+
version: 8.1.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: 2017-12-
|
13
|
+
date: 2017-12-11 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
@@ -265,6 +265,7 @@ files:
|
|
265
265
|
- lib/generators/paper_trail/templates/create_versions.rb.erb
|
266
266
|
- lib/paper_trail.rb
|
267
267
|
- lib/paper_trail/attribute_serializers/README.md
|
268
|
+
- lib/paper_trail/attribute_serializers/attribute_serializer_factory.rb
|
268
269
|
- lib/paper_trail/attribute_serializers/cast_attribute_serializer.rb
|
269
270
|
- lib/paper_trail/attribute_serializers/object_attribute.rb
|
270
271
|
- lib/paper_trail/attribute_serializers/object_changes_attribute.rb
|
@@ -293,6 +294,7 @@ files:
|
|
293
294
|
- lib/paper_trail/reifiers/has_one.rb
|
294
295
|
- lib/paper_trail/serializers/json.rb
|
295
296
|
- lib/paper_trail/serializers/yaml.rb
|
297
|
+
- lib/paper_trail/type_serializers/postgres_array_serializer.rb
|
296
298
|
- lib/paper_trail/version_association_concern.rb
|
297
299
|
- lib/paper_trail/version_concern.rb
|
298
300
|
- lib/paper_trail/version_number.rb
|