paper_trail 8.1.0 → 8.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 35be7a120b219b65fcc01eaad84678dcb9f3400bf91202e08965d32b08ca0f4c
4
- data.tar.gz: 07924178fab1058f7ee256722ae2370dc2f424cb2821af79dd45f58449f08ce4
3
+ metadata.gz: 389976a20a0d3d80ff31006b9ad5f58e8c66b2678d96eb6bdf25d461d28dc182
4
+ data.tar.gz: 0d7a51d9715a65cd7a0f509d9db888a8b6b01514c9f6a56bd13940fced350361
5
5
  SHA512:
6
- metadata.gz: e7cf8bf09991e914d93ff7a0983d9143c479fddeb57cf7a0eb9e0833aa8c6a7162576b287823aedaf9cef3376bf7a337c0780fc24e02b66562f02c38ef8b12e3
7
- data.tar.gz: 0cfa94e51ea6609874cf8fd86caee523fe3231da5ef067c03d6f01fb9c848d44a5e46ca02a2cb759a6cc02e7b75749270eac3eb63221dfa9aa5efbdd893bff9a
6
+ metadata.gz: 26239968c3d59c0a745d66990d053f2ca9a03bce8dfd31bbd4d811abcb05e58cad0fa1cf7d4ac7882325861e07edacb295b24c34ae29f7b880d23bff9ba718bc
7
+ data.tar.gz: d6c8b8104f81dfd31ecb64cc4ec936fb22d3b079ac686628f36e3c770c6f768d1953a47c195f11587ffd9e2afc840616364bf89f5893ea93e6dbd1cdf6064697
@@ -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 field in the versions table must now be
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.type_for_attribute(attr).serialize(val)
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.type_for_attribute(attr).deserialize(val)
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
- @set_paper_trail_whodunnit_called = true
70
- ::PaperTrail.whodunnit = user_for_paper_trail if ::PaperTrail.enabled_for_controller?
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
- ::PaperTrail.controller_info = info_for_paper_trail if ::PaperTrail.enabled_for_controller?
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
@@ -7,7 +7,7 @@ module PaperTrail
7
7
  module VERSION
8
8
  MAJOR = 8
9
9
  MINOR = 1
10
- TINY = 0
10
+ TINY = 1
11
11
  PRE = nil
12
12
 
13
13
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".").freeze
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.0
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-01 00:00:00.000000000 Z
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