paper_trail 10.0.1 → 10.1.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
- SHA256:
3
- metadata.gz: 47c38caa07b2338ea8be0891289d04d2028487d81a4897b1cda2fb6ca2dcc7b1
4
- data.tar.gz: 266c0c65f7c34c4d8be8ee698c605a4e887b4954005a16f074aa50da6c721c42
2
+ SHA1:
3
+ metadata.gz: ac357832683a239eb259f30fea0d05701ddd634f
4
+ data.tar.gz: 1745e41be7c599090c4fd947822a30a6ad18b6ee
5
5
  SHA512:
6
- metadata.gz: 5d9c17c2548902f41d6872dd97cd29cbce9db1793f5e71790d094f93c3287e32f2142429b30d808ee6370b88b84d4b8d5d6df30da487de2ef89c323375a392e9
7
- data.tar.gz: ff8e7415e8b4fbc2928140d746aef3c103df47d591a139478441e9e1878b1cb90eee05d7b7eb38dbaa33c48126e9f1bc9662f1113c924b069a892da2dc0e429f
6
+ metadata.gz: efa1906f7569fd7cb9eab56ad5d70daed5739714cd52197e97e2057cdb311b3016c3b36c3b4992c1cb75cc26ede53e42b481424fedc4fc40f47adc3902c7f772
7
+ data.tar.gz: b4e4976c7273d397ea6a657debd40b4aa4354bce68b59c7e70bb28cf928e46c210d4085e44314d3aa8b3d8889fb46762375987bf904a989751d732056f54b592
@@ -22,7 +22,6 @@ module PaperTrail
22
22
  )
23
23
 
24
24
  desc "Generates (but does not run) a migration to add a versions table." \
25
- " Also generates an initializer file for configuring PaperTrail." \
26
25
  " See section 5.c. Generators in README.md for more information."
27
26
 
28
27
  def create_migration_file
@@ -24,8 +24,7 @@ module PaperTrail
24
24
  desc: "Store changeset (diff) with each version"
25
25
  )
26
26
 
27
- desc "Generates (but does not run) a migration to add a versions table." \
28
- " Also generates an initializer file for configuring PaperTrail"
27
+ desc "Generates (but does not run) a migration to add a versions table."
29
28
 
30
29
  def create_migration_file
31
30
  add_paper_trail_migration("create_versions")
@@ -10,7 +10,7 @@ module PaperTrail
10
10
  include Singleton
11
11
 
12
12
  E_PT_AT_REMOVED = <<-EOS.squish
13
- Association Tracking for PaperTrail has been extracted to a seperate gem.
13
+ Association Tracking for PaperTrail has been extracted to a separate gem.
14
14
  To use it, please add `paper_trail-association_tracking` to your Gemfile.
15
15
  If you don't use it (most people don't, that's the default) and you set
16
16
  `track_associations = false` somewhere (probably a rails initializer) you
@@ -21,7 +21,8 @@ module PaperTrail
21
21
  :association_reify_error_behaviour,
22
22
  :object_changes_adapter,
23
23
  :serializer,
24
- :version_limit
24
+ :version_limit,
25
+ :has_paper_trail_defaults
25
26
  )
26
27
 
27
28
  def initialize
@@ -31,6 +32,7 @@ module PaperTrail
31
32
 
32
33
  # Variables which affect all threads, whose access is *not* synchronized.
33
34
  @serializer = PaperTrail::Serializers::YAML
35
+ @has_paper_trail_defaults = {}
34
36
  end
35
37
 
36
38
  # Indicates whether PaperTrail is on or off. Default: true.
@@ -23,18 +23,18 @@ module PaperTrail
23
23
  # Options:
24
24
  #
25
25
  # - :on - The events to track (optional; defaults to all of them). Set
26
- # to an array of `:create`, `:update`, `:destroy` as desired.
27
- # - :class_name - The name of a custom Version class. This class should
28
- # inherit from `PaperTrail::Version`.
26
+ # to an array of `:create`, `:update`, `:destroy` and `:touch` as desired.
27
+ # - :class_name (deprecated) - The name of a custom Version class that
28
+ # includes `PaperTrail::VersionConcern`.
29
29
  # - :ignore - An array of attributes for which a new `Version` will not be
30
- # created if only they change. It can also aceept a Hash as an
30
+ # created if only they change. It can also accept a Hash as an
31
31
  # argument where the key is the attribute to ignore (a `String` or
32
32
  # `Symbol`), which will only be ignored if the value is a `Proc` which
33
33
  # returns truthily.
34
34
  # - :if, :unless - Procs that allow to specify conditions when to save
35
35
  # versions for an object.
36
36
  # - :only - Inverse of `ignore`. A new `Version` will be created only
37
- # for these attributes if supplied it can also aceept a Hash as an
37
+ # for these attributes if supplied it can also accept a Hash as an
38
38
  # argument where the key is the attribute to track (a `String` or
39
39
  # `Symbol`), which will only be counted if the value is a `Proc` which
40
40
  # returns truthily.
@@ -47,20 +47,25 @@ module PaperTrail
47
47
  # are called with `self`, i.e. the model with the paper trail). See
48
48
  # `PaperTrail::Controller.info_for_paper_trail` for how to store data
49
49
  # from the controller.
50
- # - :versions - The name to use for the versions association. Default
51
- # is `:versions`.
50
+ # - :versions - Either,
51
+ # - A String (deprecated) - The name to use for the versions
52
+ # association. Default is `:versions`.
53
+ # - A Hash - options passed to `has_many`, plus `name:` and `scope:`.
52
54
  # - :version - The name to use for the method which returns the version
53
55
  # the instance was reified from. Default is `:version`.
54
- # - :join_tables - If the model has a has_and_belongs_to_many relation
55
- # with an unpapertrailed model, passing the name of the association to
56
- # the join_tables option will paper trail the join table but not save
57
- # the other model, allowing reification of the association but with the
58
- # other models latest state (if the other model is paper trailed, this
59
- # option does nothing)
56
+ #
57
+ # Plugins like the experimental `paper_trail-association_tracking` gem
58
+ # may accept additional options.
59
+ #
60
+ # You can define a default set of options via the configurable
61
+ # `PaperTrail.config.has_paper_trail_defaults` hash in your applications
62
+ # initializer. The hash can contain any of the following options and will
63
+ # provide an overridable default for all models.
60
64
  #
61
65
  # @api public
62
66
  def has_paper_trail(options = {})
63
- paper_trail.setup(options)
67
+ defaults = PaperTrail.config.has_paper_trail_defaults
68
+ paper_trail.setup(defaults.merge(options))
64
69
  end
65
70
 
66
71
  # @api public
@@ -18,6 +18,16 @@ module PaperTrail
18
18
  `abstract_class`. This is fine, but all application models must be
19
19
  configured to use concrete (not abstract) version models.
20
20
  STR
21
+ DPR_PASSING_ASSOC_NAME_DIRECTLY_TO_VERSIONS_OPTION = <<~STR.squish
22
+ Passing versions association name as `has_paper_trail versions: %{versions_name}`
23
+ is deprecated. Use `has_paper_trail versions: {name: %{versions_name}}` instead.
24
+ The hash you pass to `versions:` is now passed directly to `has_many`.
25
+ STR
26
+ DPR_CLASS_NAME_OPTION = <<~STR.squish
27
+ Passing Version class name as `has_paper_trail class_name: %{class_name}`
28
+ is deprecated. Use `has_paper_trail versions: {class_name: %{class_name}}`
29
+ instead. The hash you pass to `versions:` is now passed directly to `has_many`.
30
+ STR
21
31
 
22
32
  def initialize(model_class)
23
33
  @model_class = model_class
@@ -129,6 +139,65 @@ module PaperTrail
129
139
  ::ActiveRecord::Base.belongs_to_required_by_default
130
140
  end
131
141
 
142
+ def check_version_class_name(options)
143
+ # @api private - `version_class_name`
144
+ @model_class.class_attribute :version_class_name
145
+ if options[:class_name]
146
+ ::ActiveSupport::Deprecation.warn(
147
+ format(
148
+ DPR_CLASS_NAME_OPTION,
149
+ class_name: options[:class_name].inspect
150
+ ),
151
+ caller(1)
152
+ )
153
+ options[:versions][:class_name] = options[:class_name]
154
+ end
155
+ @model_class.version_class_name = options[:versions][:class_name] || "PaperTrail::Version"
156
+ assert_concrete_activerecord_class(@model_class.version_class_name)
157
+ end
158
+
159
+ def check_versions_association_name(options)
160
+ # @api private - versions_association_name
161
+ @model_class.class_attribute :versions_association_name
162
+ @model_class.versions_association_name = options[:versions][:name] || :versions
163
+ end
164
+
165
+ def define_has_many_versions(options)
166
+ options = ensure_versions_option_is_hash(options)
167
+ check_version_class_name(options)
168
+ check_versions_association_name(options)
169
+ scope = get_versions_scope(options)
170
+ @model_class.has_many(
171
+ @model_class.versions_association_name,
172
+ scope,
173
+ class_name: @model_class.version_class_name,
174
+ as: :item,
175
+ **options[:versions].except(:name, :scope)
176
+ )
177
+ end
178
+
179
+ def ensure_versions_option_is_hash(options)
180
+ unless options[:versions].is_a?(Hash)
181
+ if options[:versions]
182
+ ::ActiveSupport::Deprecation.warn(
183
+ format(
184
+ DPR_PASSING_ASSOC_NAME_DIRECTLY_TO_VERSIONS_OPTION,
185
+ versions_name: options[:versions].inspect
186
+ ),
187
+ caller(1)
188
+ )
189
+ end
190
+ options[:versions] = {
191
+ name: options[:versions]
192
+ }
193
+ end
194
+ options
195
+ end
196
+
197
+ def get_versions_scope(options)
198
+ options[:versions][:scope] || -> { order(model.timestamp_sort_order) }
199
+ end
200
+
132
201
  def setup_associations(options)
133
202
  # @api private - version_association_name
134
203
  @model_class.class_attribute :version_association_name
@@ -138,29 +207,10 @@ module PaperTrail
138
207
  # @api public
139
208
  @model_class.send :attr_accessor, @model_class.version_association_name
140
209
 
141
- # @api private - `version_class_name` - However, `rails_admin` has been
142
- # using it since 2014 (see `rails_admin/extensions/paper_trail/auditing_adapter.rb`,
143
- # https://github.com/sferik/rails_admin/commit/959e1bd4e47e0369d264b58bbbe972ff863767cd)
144
- # In PR _____ () we ask them to use `paper_trail_options` instead.
145
- @model_class.class_attribute :version_class_name
146
- @model_class.version_class_name = options[:class_name] || "PaperTrail::Version"
147
-
148
- # @api private - versions_association_name
149
- @model_class.class_attribute :versions_association_name
150
- @model_class.versions_association_name = options[:versions] || :versions
151
-
152
210
  # @api public - paper_trail_event
153
211
  @model_class.send :attr_accessor, :paper_trail_event
154
212
 
155
- assert_concrete_activerecord_class(@model_class.version_class_name)
156
-
157
- # @api public
158
- @model_class.has_many(
159
- @model_class.versions_association_name,
160
- -> { order(model.timestamp_sort_order) },
161
- class_name: @model_class.version_class_name,
162
- as: :item
163
- )
213
+ define_has_many_versions(options)
164
214
  end
165
215
 
166
216
  def setup_callbacks_from_options(options_on = [])
@@ -170,9 +220,10 @@ module PaperTrail
170
220
  end
171
221
 
172
222
  def setup_options(options)
173
- # @api public - paper_trail_options - Let's encourage plugins to use
174
- # eg. `paper_trail_options[:class_name]` rather than `version_class_name`
175
- # because the former is documented and the latter is not.
223
+ # @api public - paper_trail_options - Let's encourage plugins to use eg.
224
+ # `paper_trail_options[:versions][:class_name]` rather than
225
+ # `version_class_name` because the former is documented and the latter is
226
+ # not.
176
227
  @model_class.class_attribute :paper_trail_options
177
228
  @model_class.paper_trail_options = options.dup
178
229
 
@@ -29,8 +29,7 @@ module PaperTrail
29
29
  private
30
30
 
31
31
  def active_record_pre_502?
32
- ::ActiveRecord::VERSION::MAJOR < 5 ||
33
- (::ActiveRecord::VERSION::MINOR.zero? && ::ActiveRecord::VERSION::TINY < 2)
32
+ ::ActiveRecord.gem_version < Gem::Version.new("5.0.2")
34
33
  end
35
34
 
36
35
  def serialize_with_ar(array)
@@ -8,8 +8,8 @@ module PaperTrail
8
8
  # People are encouraged to use `PaperTrail.gem_version` instead.
9
9
  module VERSION
10
10
  MAJOR = 10
11
- MINOR = 0
12
- TINY = 1
11
+ MINOR = 1
12
+ TINY = 0
13
13
 
14
14
  # Set PRE to nil unless it's a pre-release (beta, rc, etc.)
15
15
  PRE = nil
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.0.1
4
+ version: 10.1.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-09-01 00:00:00.000000000 Z
13
+ date: 2018-12-04 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: '5.3'
24
+ version: '6.0'
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: '5.3'
34
+ version: '6.0'
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: request_store
37
37
  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.7.6
288
+ rubygems_version: 2.6.14.3
289
289
  signing_key:
290
290
  specification_version: 4
291
291
  summary: Track changes to your models.