paper_trail 10.1.0 → 10.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ac357832683a239eb259f30fea0d05701ddd634f
4
- data.tar.gz: 1745e41be7c599090c4fd947822a30a6ad18b6ee
3
+ metadata.gz: 9a180f82e731345bd4b9f46971ee6ca61753f82e
4
+ data.tar.gz: c32cde31e4da02b078d13c8c2667a6b0c49c4110
5
5
  SHA512:
6
- metadata.gz: efa1906f7569fd7cb9eab56ad5d70daed5739714cd52197e97e2057cdb311b3016c3b36c3b4992c1cb75cc26ede53e42b481424fedc4fc40f47adc3902c7f772
7
- data.tar.gz: b4e4976c7273d397ea6a657debd40b4aa4354bce68b59c7e70bb28cf928e46c210d4085e44314d3aa8b3d8889fb46762375987bf904a989751d732056f54b592
6
+ metadata.gz: bd84d2586c73b9f08e44fabb1298a6e530ecf25953da0a05a41a925870720e6c05eb74474321816b51dd24cceb1d14b0658f685ac0c68a91de3ff6e7c2e0525b
7
+ data.tar.gz: fb8e6814903909666d842d43b68b5ef97e5c207a8193d34a5d199f8405fb83565c87ba86925c58148720debde25bdd442f712ef75b9acaf8b3d86a6c71978191
@@ -125,6 +125,10 @@ module PaperTrail
125
125
  end
126
126
  end
127
127
 
128
+ # We use the `on_load` "hook" instead of `ActiveRecord::Base.include` because we
129
+ # don't want to cause all of AR to be autloaded yet. See
130
+ # https://guides.rubyonrails.org/engines.html#what-are-on-load-hooks-questionmark
131
+ # to learn more about `on_load`.
128
132
  ActiveSupport.on_load(:active_record) do
129
133
  include PaperTrail::Model
130
134
  end
@@ -106,38 +106,9 @@ module PaperTrail
106
106
  (changed_in_latest_version - ignore) - skip
107
107
  end
108
108
 
109
- # Rails 5.1 changed the API of `ActiveRecord::Dirty`. See
110
- # https://github.com/paper-trail-gem/paper_trail/pull/899
111
- #
112
109
  # @api private
113
110
  def changed_in_latest_version
114
- if @in_after_callback && RAILS_GTE_5_1
115
- @record.saved_changes.keys
116
- else
117
- @record.changed
118
- end
119
- end
120
-
121
- # @api private
122
- def prepare_object_changes(changes)
123
- changes = serialize_object_changes(changes)
124
- changes = recordable_object_changes(changes)
125
- changes
126
- end
127
-
128
- # @api private
129
- def serialize_object_changes(changes)
130
- AttributeSerializers::ObjectChangesAttribute.
131
- new(@record.class).
132
- serialize(changes)
133
- changes.to_hash
134
- end
135
-
136
- # @api private
137
- def notable_changes
138
- changes_in_latest_version.delete_if { |k, _v|
139
- !notably_changed.include?(k)
140
- }
111
+ changes_in_latest_version.keys
141
112
  end
142
113
 
143
114
  # Rails 5.1 changed the API of `ActiveRecord::Dirty`. See
@@ -220,6 +191,13 @@ module PaperTrail
220
191
  end
221
192
  end
222
193
 
194
+ # @api private
195
+ def notable_changes
196
+ changes_in_latest_version.delete_if { |k, _v|
197
+ !notably_changed.include?(k)
198
+ }
199
+ end
200
+
223
201
  # @api private
224
202
  def notably_changed
225
203
  only = @record.paper_trail_options[:only].dup
@@ -245,6 +223,13 @@ module PaperTrail
245
223
  attrs
246
224
  end
247
225
 
226
+ # @api private
227
+ def prepare_object_changes(changes)
228
+ changes = serialize_object_changes(changes)
229
+ changes = recordable_object_changes(changes)
230
+ changes
231
+ end
232
+
248
233
  # Returns an object which can be assigned to the `object_changes`
249
234
  # attribute of a nascent version record. If the `object_changes` column is
250
235
  # a postgres `json` column, then a hash can be used in the assignment,
@@ -293,6 +278,14 @@ module PaperTrail
293
278
  PaperTrail.serializer.dump(object_attrs_for_paper_trail(is_touch))
294
279
  end
295
280
  end
281
+
282
+ # @api private
283
+ def serialize_object_changes(changes)
284
+ AttributeSerializers::ObjectChangesAttribute.
285
+ new(@record.class).
286
+ serialize(changes)
287
+ changes.to_hash
288
+ end
296
289
  end
297
290
  end
298
291
  end
@@ -22,13 +22,21 @@ module PaperTrail
22
22
  data[:object] = recordable_object(false)
23
23
  end
24
24
  if record_object_changes?
25
- # Rails' implementation returns nothing on destroy :/
26
- changes = @record.attributes.map { |attr, value| [attr, [value, nil]] }.to_h
27
- data[:object_changes] = prepare_object_changes(changes)
25
+ data[:object_changes] = prepare_object_changes(notable_changes)
28
26
  end
29
27
  merge_item_subtype_into(data)
30
28
  merge_metadata_into(data)
31
29
  end
30
+
31
+ private
32
+
33
+ # Rails' implementation (eg. `@record.saved_changes`) returns nothing on
34
+ # destroy, so we have to build the hash we want.
35
+ #
36
+ # @override
37
+ def changes_in_latest_version
38
+ @record.attributes.map { |attr, value| [attr, [value, nil]] }.to_h
39
+ end
32
40
  end
33
41
  end
34
42
  end
@@ -4,11 +4,42 @@ module PaperTrail
4
4
  module Rails
5
5
  # See http://guides.rubyonrails.org/engines.html
6
6
  class Engine < ::Rails::Engine
7
+ DPR_CONFIG_ENABLED = <<~EOS.squish.freeze
8
+ The rails configuration option config.paper_trail.enabled is deprecated.
9
+ Please use PaperTrail.enabled= instead. People were getting confused
10
+ that PT has both, specifically regarding *when* each was happening. If
11
+ you'd like to keep config.paper_trail, join the discussion at
12
+ https://github.com/paper-trail-gem/paper_trail/pull/1176
13
+ EOS
14
+ private_constant :DPR_CONFIG_ENABLED
15
+ DPR_RUDELY_ENABLING = <<~EOS.squish.freeze
16
+ At some point early in the rails boot process, you have set
17
+ PaperTrail.enabled = false. PT's rails engine is now overriding your
18
+ setting, and setting it to true. We're not sure why, but this is how PT
19
+ has worked since 5.0, when the config.paper_trail.enabled option was
20
+ introduced. This is now deprecated. In the future, PT will not override
21
+ your setting. See
22
+ https://github.com/paper-trail-gem/paper_trail/pull/1176 for discussion.
23
+ EOS
24
+ private_constant :DPR_RUDELY_ENABLING
25
+
7
26
  paths["app/models"] << "lib/paper_trail/frameworks/active_record/models"
27
+
28
+ # --- Begin deprecated section ---
8
29
  config.paper_trail = ActiveSupport::OrderedOptions.new
9
30
  initializer "paper_trail.initialisation" do |app|
10
- PaperTrail.enabled = app.config.paper_trail.fetch(:enabled, true)
31
+ enable = app.config.paper_trail[:enabled]
32
+ if enable.nil?
33
+ unless PaperTrail.enabled?
34
+ ::ActiveSupport::Deprecation.warn(DPR_RUDELY_ENABLING)
35
+ PaperTrail.enabled = true
36
+ end
37
+ else
38
+ ::ActiveSupport::Deprecation.warn(DPR_CONFIG_ENABLED)
39
+ PaperTrail.enabled = enable
40
+ end
11
41
  end
42
+ # --- End deprecated section ---
12
43
  end
13
44
  end
14
45
  end
@@ -8,7 +8,7 @@ module PaperTrail
8
8
  # People are encouraged to use `PaperTrail.gem_version` instead.
9
9
  module VERSION
10
10
  MAJOR = 10
11
- MINOR = 1
11
+ MINOR = 2
12
12
  TINY = 0
13
13
 
14
14
  # Set PRE to nil unless it's a pre-release (beta, rc, etc.)
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.1.0
4
+ version: 10.2.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: 2018-12-04 00:00:00.000000000 Z
13
+ date: 2019-01-31 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '4.2'
22
22
  - - "<"
23
23
  - !ruby/object:Gem::Version
24
- version: '6.0'
24
+ version: '6.1'
25
25
  type: :runtime
26
26
  prerelease: false
27
27
  version_requirements: !ruby/object:Gem::Requirement
@@ -31,7 +31,7 @@ dependencies:
31
31
  version: '4.2'
32
32
  - - "<"
33
33
  - !ruby/object:Gem::Version
34
- version: '6.0'
34
+ version: '6.1'
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: request_store
37
37
  requirement: !ruby/object:Gem::Requirement
@@ -120,16 +120,16 @@ dependencies:
120
120
  name: paper_trail-association_tracking
121
121
  requirement: !ruby/object:Gem::Requirement
122
122
  requirements:
123
- - - "<"
123
+ - - "~>"
124
124
  - !ruby/object:Gem::Version
125
- version: '2'
125
+ version: 2.0.0
126
126
  type: :development
127
127
  prerelease: false
128
128
  version_requirements: !ruby/object:Gem::Requirement
129
129
  requirements:
130
- - - "<"
130
+ - - "~>"
131
131
  - !ruby/object:Gem::Version
132
- version: '2'
132
+ version: 2.0.0
133
133
  - !ruby/object:Gem::Dependency
134
134
  name: pg
135
135
  requirement: !ruby/object:Gem::Requirement
@@ -178,14 +178,14 @@ dependencies:
178
178
  requirements:
179
179
  - - "~>"
180
180
  - !ruby/object:Gem::Version
181
- version: 0.58.2
181
+ version: 0.62.0
182
182
  type: :development
183
183
  prerelease: false
184
184
  version_requirements: !ruby/object:Gem::Requirement
185
185
  requirements:
186
186
  - - "~>"
187
187
  - !ruby/object:Gem::Version
188
- version: 0.58.2
188
+ version: 0.62.0
189
189
  - !ruby/object:Gem::Dependency
190
190
  name: rubocop-rspec
191
191
  requirement: !ruby/object:Gem::Requirement
@@ -285,7 +285,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
285
285
  version: 1.3.6
286
286
  requirements: []
287
287
  rubyforge_project:
288
- rubygems_version: 2.6.14.3
288
+ rubygems_version: 2.5.2.3
289
289
  signing_key:
290
290
  specification_version: 4
291
291
  summary: Track changes to your models.