mongo_trails 10.3.1 → 14.0.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/.github/workflows/test.yml +53 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +19 -0
- data/.ruby-version +1 -0
- data/Appraisals +10 -4
- data/Gemfile +8 -1
- data/README.md +28 -6
- data/Rakefile +17 -0
- data/bin/bump-version +67 -0
- data/gemfiles/rails_7.gemfile +15 -0
- data/gemfiles/rails_7.gemfile.lock +212 -0
- data/gemfiles/rails_8.gemfile +15 -0
- data/gemfiles/rails_8.gemfile.lock +213 -0
- data/gemfiles/rails_8_1.gemfile +15 -0
- data/gemfiles/rails_8_1.gemfile.lock +143 -0
- data/lib/mongo_trails/callback_propagation.rb +77 -0
- data/lib/mongo_trails/config.rb +7 -24
- data/lib/mongo_trails/events/base.rb +5 -308
- data/lib/mongo_trails/model_config.rb +1 -232
- data/lib/mongo_trails/mongo_support/config.rb +7 -1
- data/lib/mongo_trails/mongo_support/criteria.rb +7 -0
- data/lib/mongo_trails/mongo_support/version.rb +249 -19
- data/lib/mongo_trails/mongo_support/version_commit_wrap.rb +37 -0
- data/lib/mongo_trails/mongo_support/write_version_worker.rb +11 -0
- data/lib/mongo_trails/record_trail.rb +21 -262
- data/lib/mongo_trails/version.rb +5 -0
- data/lib/mongo_trails/version_concern.rb +4 -293
- data/lib/mongo_trails.rb +13 -149
- data/mongo_trails.gemspec +19 -20
- metadata +51 -85
- data/.travis.yml +0 -13
- data/Gemfile.lock +0 -62
- data/gemfiles/rails_5.gemfile +0 -9
- data/gemfiles/rails_5.gemfile.lock +0 -63
- data/gemfiles/rails_6.gemfile +0 -9
- data/gemfiles/rails_6.gemfile.lock +0 -63
- data/lib/mongo_trails/attribute_serializers/README.md +0 -10
- data/lib/mongo_trails/attribute_serializers/attribute_serializer_factory.rb +0 -27
- data/lib/mongo_trails/attribute_serializers/cast_attribute_serializer.rb +0 -51
- data/lib/mongo_trails/attribute_serializers/object_attribute.rb +0 -41
- data/lib/mongo_trails/attribute_serializers/object_changes_attribute.rb +0 -44
- data/lib/mongo_trails/cleaner.rb +0 -60
- data/lib/mongo_trails/compatibility.rb +0 -51
- data/lib/mongo_trails/events/create.rb +0 -32
- data/lib/mongo_trails/events/destroy.rb +0 -42
- data/lib/mongo_trails/events/update.rb +0 -60
- data/lib/mongo_trails/frameworks/cucumber.rb +0 -33
- data/lib/mongo_trails/frameworks/rails/controller.rb +0 -109
- data/lib/mongo_trails/frameworks/rails/engine.rb +0 -43
- data/lib/mongo_trails/frameworks/rails.rb +0 -4
- data/lib/mongo_trails/frameworks/rspec/helpers.rb +0 -29
- data/lib/mongo_trails/frameworks/rspec.rb +0 -43
- data/lib/mongo_trails/has_paper_trail.rb +0 -86
- data/lib/mongo_trails/queries/versions/where_object.rb +0 -65
- data/lib/mongo_trails/queries/versions/where_object_changes.rb +0 -75
- data/lib/mongo_trails/record_history.rb +0 -51
- data/lib/mongo_trails/reifier.rb +0 -130
- data/lib/mongo_trails/request.rb +0 -166
- data/lib/mongo_trails/serializers/json.rb +0 -46
- data/lib/mongo_trails/serializers/yaml.rb +0 -43
- data/lib/mongo_trails/type_serializers/postgres_array_serializer.rb +0 -48
- data/lib/mongo_trails/version_number.rb +0 -23
|
@@ -1,336 +1,47 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "mongo_trails/attribute_serializers/object_changes_attribute"
|
|
4
|
-
require "mongo_trails/queries/versions/where_object"
|
|
5
|
-
require "mongo_trails/queries/versions/where_object_changes"
|
|
6
|
-
|
|
7
3
|
module PaperTrail
|
|
8
|
-
# Originally, PaperTrail did not provide this module, and all of this
|
|
9
|
-
# functionality was in `PaperTrail::Version`. That model still exists (and is
|
|
10
|
-
# used by most apps) but by moving the functionality to this module, people
|
|
11
|
-
# can include this concern instead of sub-classing the `Version` model.
|
|
12
4
|
module VersionConcern
|
|
13
5
|
extend ::ActiveSupport::Concern
|
|
14
6
|
|
|
15
|
-
# :nodoc:
|
|
16
7
|
module ClassMethods
|
|
17
|
-
def item_subtype_column_present?
|
|
18
|
-
column_names.include?("item_subtype")
|
|
19
|
-
end
|
|
20
|
-
|
|
21
8
|
def with_item_keys(item_type, item_id)
|
|
22
|
-
where(item_type: item_type
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def creates
|
|
26
|
-
where event: "create"
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def updates
|
|
30
|
-
where event: "update"
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def destroys
|
|
34
|
-
where event: "destroy"
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def not_creates
|
|
38
|
-
where "event <> ?", "create"
|
|
9
|
+
where(item_type: item_type, item_id: item_id)
|
|
39
10
|
end
|
|
40
11
|
|
|
41
12
|
def between(start_time, end_time)
|
|
42
|
-
where(:created_at.gt => start_time
|
|
13
|
+
where(:created_at.gt => start_time, :created_at.lt => end_time).order(timestamp_sort_order)
|
|
43
14
|
end
|
|
44
15
|
|
|
45
|
-
|
|
46
|
-
# possible.
|
|
47
|
-
def timestamp_sort_order(direction = "asc")
|
|
16
|
+
def timestamp_sort_order(direction = 'asc')
|
|
48
17
|
{ created_at: direction.downcase }
|
|
49
18
|
end
|
|
50
19
|
|
|
51
|
-
# Given a hash of attributes like `name: 'Joan'`, query the
|
|
52
|
-
# `versions.objects` column.
|
|
53
|
-
#
|
|
54
|
-
# ```
|
|
55
|
-
# SELECT "versions".*
|
|
56
|
-
# FROM "versions"
|
|
57
|
-
# WHERE ("versions"."object" LIKE '%
|
|
58
|
-
# name: Joan
|
|
59
|
-
# %')
|
|
60
|
-
# ```
|
|
61
|
-
#
|
|
62
|
-
# This is useful for finding versions where a given attribute had a given
|
|
63
|
-
# value. Imagine, in the example above, that Joan had changed her name
|
|
64
|
-
# and we wanted to find the versions before that change.
|
|
65
|
-
#
|
|
66
|
-
# Based on the data type of the `object` column, the appropriate SQL
|
|
67
|
-
# operator is used. For example, a text column will use `like`, and a
|
|
68
|
-
# jsonb column will use `@>`.
|
|
69
|
-
#
|
|
70
|
-
# @api public
|
|
71
|
-
def where_object(args = {})
|
|
72
|
-
raise ArgumentError, "expected to receive a Hash" unless args.is_a?(Hash)
|
|
73
|
-
Queries::Versions::WhereObject.new(self, args).execute
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
# Given a hash of attributes like `name: 'Joan'`, query the
|
|
77
|
-
# `versions.objects_changes` column.
|
|
78
|
-
#
|
|
79
|
-
# ```
|
|
80
|
-
# SELECT "versions".*
|
|
81
|
-
# FROM "versions"
|
|
82
|
-
# WHERE .. ("versions"."object_changes" LIKE '%
|
|
83
|
-
# name:
|
|
84
|
-
# - Joan
|
|
85
|
-
# %' OR "versions"."object_changes" LIKE '%
|
|
86
|
-
# name:
|
|
87
|
-
# -%
|
|
88
|
-
# - Joan
|
|
89
|
-
# %')
|
|
90
|
-
# ```
|
|
91
|
-
#
|
|
92
|
-
# This is useful for finding versions immediately before and after a given
|
|
93
|
-
# attribute had a given value. Imagine, in the example above, that someone
|
|
94
|
-
# changed their name to Joan and we wanted to find the versions
|
|
95
|
-
# immediately before and after that change.
|
|
96
|
-
#
|
|
97
|
-
# Based on the data type of the `object` column, the appropriate SQL
|
|
98
|
-
# operator is used. For example, a text column will use `like`, and a
|
|
99
|
-
# jsonb column will use `@>`.
|
|
100
|
-
#
|
|
101
|
-
# @api public
|
|
102
|
-
def where_object_changes(args = {})
|
|
103
|
-
raise ArgumentError, "expected to receive a Hash" unless args.is_a?(Hash)
|
|
104
|
-
Queries::Versions::WhereObjectChanges.new(self, args).execute
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
def primary_key_is_int?
|
|
108
|
-
@primary_key_is_int ||= columns_hash[primary_key].type == :integer
|
|
109
|
-
rescue StandardError # TODO: Rescue something more specific
|
|
110
|
-
true
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
# Returns whether the `object` column is using the `json` type supported
|
|
114
|
-
# by PostgreSQL.
|
|
115
20
|
def object_col_is_json?
|
|
116
|
-
# %i[json jsonb].include?(columns_hash["object"].type)
|
|
117
21
|
true
|
|
118
22
|
end
|
|
119
23
|
|
|
120
|
-
# Returns whether the `object_changes` column is using the `json` type
|
|
121
|
-
# supported by PostgreSQL.
|
|
122
24
|
def object_changes_col_is_json?
|
|
123
|
-
# %i[json jsonb].include?(columns_hash["object_changes"].try(:type))
|
|
124
25
|
true
|
|
125
26
|
end
|
|
126
27
|
|
|
127
|
-
# Returns versions before `obj`.
|
|
128
|
-
#
|
|
129
|
-
# @param obj - a `Version` or a timestamp
|
|
130
|
-
# @param timestamp_arg - boolean - When true, `obj` is a timestamp.
|
|
131
|
-
# Default: false.
|
|
132
|
-
# @return `ActiveRecord::Relation`
|
|
133
|
-
# @api public
|
|
134
|
-
def preceding(obj, timestamp_arg = false)
|
|
135
|
-
if timestamp_arg != true && primary_key_is_int?
|
|
136
|
-
preceding_by_id(obj)
|
|
137
|
-
else
|
|
138
|
-
preceding_by_timestamp(obj)
|
|
139
|
-
end
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
# Returns versions after `obj`.
|
|
143
|
-
#
|
|
144
|
-
# @param obj - a `Version` or a timestamp
|
|
145
|
-
# @param timestamp_arg - boolean - When true, `obj` is a timestamp.
|
|
146
|
-
# Default: false.
|
|
147
|
-
# @return `ActiveRecord::Relation`
|
|
148
|
-
# @api public
|
|
149
|
-
def subsequent(obj, timestamp_arg = false)
|
|
150
|
-
if timestamp_arg != true && primary_key_is_int?
|
|
151
|
-
subsequent_by_id(obj)
|
|
152
|
-
else
|
|
153
|
-
subsequent_by_timestamp(obj)
|
|
154
|
-
end
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
private
|
|
158
|
-
|
|
159
|
-
# @api private
|
|
160
28
|
def preceding_by_id(obj)
|
|
161
29
|
where(:integer_id.lt => obj.integer_id).order(integer_id: :desc)
|
|
162
30
|
end
|
|
163
31
|
|
|
164
|
-
# @api private
|
|
165
32
|
def preceding_by_timestamp(obj)
|
|
166
33
|
obj = obj.send(:created_at) if obj.is_a?(self)
|
|
167
|
-
where(:created_at.lt => obj).order(timestamp_sort_order(
|
|
34
|
+
where(:created_at.lt => obj).order(timestamp_sort_order('desc'))
|
|
168
35
|
end
|
|
169
36
|
|
|
170
|
-
# @api private
|
|
171
37
|
def subsequent_by_id(version)
|
|
172
38
|
where(:integer_id.gt => version.integer_id).order(integer_id: :asc)
|
|
173
39
|
end
|
|
174
40
|
|
|
175
|
-
# @api private
|
|
176
41
|
def subsequent_by_timestamp(obj)
|
|
177
42
|
obj = obj.send(:created_at) if obj.is_a?(self)
|
|
178
43
|
where(:created_at.gt => obj).order(timestamp_sort_order)
|
|
179
44
|
end
|
|
180
45
|
end
|
|
181
|
-
|
|
182
|
-
# @api private
|
|
183
|
-
def object_deserialized
|
|
184
|
-
if self.class.object_col_is_json?
|
|
185
|
-
object
|
|
186
|
-
else
|
|
187
|
-
PaperTrail.serializer.load(object)
|
|
188
|
-
end
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
# Restore the item from this version.
|
|
192
|
-
#
|
|
193
|
-
# Options:
|
|
194
|
-
#
|
|
195
|
-
# - :mark_for_destruction
|
|
196
|
-
# - `true` - Mark the has_one/has_many associations that did not exist in
|
|
197
|
-
# the reified version for destruction, instead of removing them.
|
|
198
|
-
# - `false` - Default. Useful for persisting the reified version.
|
|
199
|
-
# - :dup
|
|
200
|
-
# - `false` - Default.
|
|
201
|
-
# - `true` - Always create a new object instance. Useful for
|
|
202
|
-
# comparing two versions of the same object.
|
|
203
|
-
# - :unversioned_attributes
|
|
204
|
-
# - `:nil` - Default. Attributes undefined in version record are set to
|
|
205
|
-
# nil in reified record.
|
|
206
|
-
# - `:preserve` - Attributes undefined in version record are not modified.
|
|
207
|
-
#
|
|
208
|
-
def reify(options = {})
|
|
209
|
-
unless self.class.fields.keys.include? "object"
|
|
210
|
-
raise "reify can't be called without an object column"
|
|
211
|
-
end
|
|
212
|
-
return nil if object.nil?
|
|
213
|
-
::PaperTrail::Reifier.reify(self, options)
|
|
214
|
-
end
|
|
215
|
-
|
|
216
|
-
# Returns what changed in this version of the item.
|
|
217
|
-
# `ActiveModel::Dirty#changes`. returns `nil` if your `versions` table does
|
|
218
|
-
# not have an `object_changes` text column.
|
|
219
|
-
def changeset
|
|
220
|
-
return nil unless self.class.fields.keys.include? "object_changes"
|
|
221
|
-
@changeset ||= load_changeset
|
|
222
|
-
end
|
|
223
|
-
|
|
224
|
-
# Returns who put the item into the state stored in this version.
|
|
225
|
-
def paper_trail_originator
|
|
226
|
-
@paper_trail_originator ||= previous.try(:whodunnit)
|
|
227
|
-
end
|
|
228
|
-
|
|
229
|
-
# Returns who changed the item from the state it had in this version. This
|
|
230
|
-
# is an alias for `whodunnit`.
|
|
231
|
-
def terminator
|
|
232
|
-
@terminator ||= whodunnit
|
|
233
|
-
end
|
|
234
|
-
alias version_author terminator
|
|
235
|
-
|
|
236
|
-
def sibling_versions(reload = false)
|
|
237
|
-
if reload || !defined?(@sibling_versions) || @sibling_versions.nil?
|
|
238
|
-
@sibling_versions = self.class.with_item_keys(item_type, item_id)
|
|
239
|
-
end
|
|
240
|
-
@sibling_versions
|
|
241
|
-
end
|
|
242
|
-
|
|
243
|
-
def next
|
|
244
|
-
@next ||= sibling_versions.subsequent(self).first
|
|
245
|
-
end
|
|
246
|
-
|
|
247
|
-
def previous
|
|
248
|
-
@previous ||= sibling_versions.preceding(self).first
|
|
249
|
-
end
|
|
250
|
-
|
|
251
|
-
# Returns an integer representing the chronological position of the
|
|
252
|
-
# version among its siblings (see `sibling_versions`). The "create" event,
|
|
253
|
-
# for example, has an index of 0.
|
|
254
|
-
# @api public
|
|
255
|
-
def index
|
|
256
|
-
@index ||= RecordHistory.new(sibling_versions, self.class).index(self)
|
|
257
|
-
end
|
|
258
|
-
|
|
259
|
-
private
|
|
260
|
-
|
|
261
|
-
# @api private
|
|
262
|
-
def load_changeset
|
|
263
|
-
if PaperTrail.config.object_changes_adapter&.respond_to?(:load_changeset)
|
|
264
|
-
return PaperTrail.config.object_changes_adapter.load_changeset(self)
|
|
265
|
-
end
|
|
266
|
-
|
|
267
|
-
# First, deserialize the `object_changes` column.
|
|
268
|
-
changes = HashWithIndifferentAccess.new(object_changes_deserialized)
|
|
269
|
-
|
|
270
|
-
# The next step is, perhaps unfortunately, called "de-serialization",
|
|
271
|
-
# and appears to be responsible for custom attribute serializers. For an
|
|
272
|
-
# example of a custom attribute serializer, see
|
|
273
|
-
# `Person::TimeZoneSerializer` in the test suite.
|
|
274
|
-
#
|
|
275
|
-
# Is `item.class` good enough? Does it handle `inheritance_column`
|
|
276
|
-
# as well as `Reifier#version_reification_class`? We were using
|
|
277
|
-
# `item_type.constantize`, but that is problematic when the STI parent
|
|
278
|
-
# is not versioned. (See `Vehicle` and `Car` in the test suite).
|
|
279
|
-
#
|
|
280
|
-
# Note: `item` returns nil if `event` is "destroy".
|
|
281
|
-
unless item.nil?
|
|
282
|
-
AttributeSerializers::ObjectChangesAttribute.
|
|
283
|
-
new(item.class).
|
|
284
|
-
deserialize(changes)
|
|
285
|
-
end
|
|
286
|
-
|
|
287
|
-
# Finally, return a Hash mapping each attribute name to
|
|
288
|
-
# a two-element array representing before and after.
|
|
289
|
-
changes
|
|
290
|
-
end
|
|
291
|
-
|
|
292
|
-
# If the `object_changes` column is a Postgres JSON column, then
|
|
293
|
-
# ActiveRecord will deserialize it for us. Otherwise, it's a string column
|
|
294
|
-
# and we must deserialize it ourselves.
|
|
295
|
-
# @api private
|
|
296
|
-
def object_changes_deserialized
|
|
297
|
-
if self.class.object_changes_col_is_json?
|
|
298
|
-
object_changes
|
|
299
|
-
else
|
|
300
|
-
begin
|
|
301
|
-
PaperTrail.serializer.load(object_changes)
|
|
302
|
-
rescue StandardError # TODO: Rescue something more specific
|
|
303
|
-
{}
|
|
304
|
-
end
|
|
305
|
-
end
|
|
306
|
-
end
|
|
307
|
-
|
|
308
|
-
# Enforces the `version_limit`, if set. Default: no limit.
|
|
309
|
-
# @api private
|
|
310
|
-
def enforce_version_limit!
|
|
311
|
-
limit = version_limit
|
|
312
|
-
return unless limit.is_a? Numeric
|
|
313
|
-
previous_versions = sibling_versions.not_creates.
|
|
314
|
-
order(self.class.timestamp_sort_order("asc"))
|
|
315
|
-
return unless previous_versions.size > limit
|
|
316
|
-
excess_versions = previous_versions - previous_versions.last(limit)
|
|
317
|
-
excess_versions.map(&:destroy)
|
|
318
|
-
end
|
|
319
|
-
|
|
320
|
-
# See docs section 2.e. Limiting the Number of Versions Created.
|
|
321
|
-
# The version limit can be global or per-model.
|
|
322
|
-
#
|
|
323
|
-
# @api private
|
|
324
|
-
#
|
|
325
|
-
# TODO: Duplication: similar `constantize` in Reifier#version_reification_class
|
|
326
|
-
def version_limit
|
|
327
|
-
if self.class.item_subtype_column_present?
|
|
328
|
-
klass = (item_subtype || item_type).constantize
|
|
329
|
-
if klass&.paper_trail_options&.key?(:limit)
|
|
330
|
-
return klass.paper_trail_options[:limit]
|
|
331
|
-
end
|
|
332
|
-
end
|
|
333
|
-
PaperTrail.config.version_limit
|
|
334
|
-
end
|
|
335
46
|
end
|
|
336
47
|
end
|
data/lib/mongo_trails.rb
CHANGED
|
@@ -1,154 +1,18 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
require
|
|
3
|
+
require 'paper_trail'
|
|
4
|
+
require 'paper_trail/version_concern'
|
|
5
|
+
require 'paper_trail/model_config'
|
|
6
|
+
require 'paper_trail/record_trail'
|
|
7
|
+
|
|
8
|
+
require 'mongo_trails/version'
|
|
9
|
+
require 'mongo_trails/config'
|
|
10
|
+
require 'mongo_trails/callback_propagation'
|
|
11
|
+
require 'mongo_trails/events/base'
|
|
12
|
+
require 'mongo_trails/model_config'
|
|
13
|
+
require 'mongo_trails/version_concern'
|
|
14
|
+
require 'mongo_trails/record_trail'
|
|
10
15
|
|
|
11
|
-
# AR is required for, eg. has_paper_trail.rb, so we could put this `require` in
|
|
12
|
-
# all of those files, but it seems easier to troubleshoot if we just make sure
|
|
13
|
-
# AR is loaded here before loading *any* of PT. See discussion of
|
|
14
|
-
# performance/simplicity tradeoff for activesupport above.
|
|
15
|
-
require "active_record"
|
|
16
|
-
|
|
17
|
-
require "request_store"
|
|
18
|
-
require "mongo_trails/cleaner"
|
|
19
|
-
require "mongo_trails/compatibility"
|
|
20
|
-
require "mongo_trails/config"
|
|
21
|
-
require "mongo_trails/has_paper_trail"
|
|
22
|
-
require "mongo_trails/record_history"
|
|
23
|
-
require "mongo_trails/reifier"
|
|
24
|
-
require "mongo_trails/request"
|
|
25
|
-
require "mongo_trails/version_concern"
|
|
26
|
-
require "mongo_trails/version_number"
|
|
27
|
-
require "mongo_trails/serializers/json"
|
|
28
|
-
require "mongo_trails/serializers/yaml"
|
|
29
|
-
|
|
30
|
-
# An ActiveRecord extension that tracks changes to your models, for auditing or
|
|
31
|
-
# versioning.
|
|
32
|
-
module PaperTrail
|
|
33
|
-
E_RAILS_NOT_LOADED = <<-EOS.squish.freeze
|
|
34
|
-
PaperTrail has been loaded too early, before rails is loaded. This can
|
|
35
|
-
happen when another gem defines the ::Rails namespace, then PT is loaded,
|
|
36
|
-
all before rails is loaded. You may want to reorder your Gemfile, or defer
|
|
37
|
-
the loading of PT by using `require: false` and a manual require elsewhere.
|
|
38
|
-
EOS
|
|
39
|
-
E_TIMESTAMP_FIELD_CONFIG = <<-EOS.squish.freeze
|
|
40
|
-
PaperTrail.timestamp_field= has been removed, without replacement. It is no
|
|
41
|
-
longer configurable. The timestamp column in the versions table must now be
|
|
42
|
-
named created_at.
|
|
43
|
-
EOS
|
|
44
|
-
|
|
45
|
-
extend PaperTrail::Cleaner
|
|
46
|
-
|
|
47
|
-
class << self
|
|
48
|
-
# Switches PaperTrail on or off, for all threads.
|
|
49
|
-
# @api public
|
|
50
|
-
def enabled=(value)
|
|
51
|
-
PaperTrail.config.enabled = value
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
# Returns `true` if PaperTrail is on, `false` otherwise. This is the
|
|
55
|
-
# on/off switch that affects all threads. Enabled by default.
|
|
56
|
-
# @api public
|
|
57
|
-
def enabled?
|
|
58
|
-
!!PaperTrail.config.enabled
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
# Returns PaperTrail's `::Gem::Version`, convenient for comparisons. This is
|
|
62
|
-
# recommended over `::PaperTrail::VERSION::STRING`.
|
|
63
|
-
#
|
|
64
|
-
# Added in 7.0.0
|
|
65
|
-
#
|
|
66
|
-
# @api public
|
|
67
|
-
def gem_version
|
|
68
|
-
::Gem::Version.new(VERSION::STRING)
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
# Set variables for the current request, eg. whodunnit.
|
|
72
|
-
#
|
|
73
|
-
# All request-level variables are now managed here, as of PT 9. Having the
|
|
74
|
-
# word "request" right there in your application code will remind you that
|
|
75
|
-
# these variables only affect the current request, not all threads.
|
|
76
|
-
#
|
|
77
|
-
# Given a block, temporarily sets the given `options`, executes the block,
|
|
78
|
-
# and returns the value of the block.
|
|
79
|
-
#
|
|
80
|
-
# Without a block, this currently just returns `PaperTrail::Request`.
|
|
81
|
-
# However, please do not use `PaperTrail::Request` directly. Currently,
|
|
82
|
-
# `Request` is a `Module`, but in the future it is quite possible we may
|
|
83
|
-
# make it a `Class`. If we make such a choice, we will not provide any
|
|
84
|
-
# warning and will not treat it as a breaking change. You've been warned :)
|
|
85
|
-
#
|
|
86
|
-
# @api public
|
|
87
|
-
def request(options = nil, &block)
|
|
88
|
-
if options.nil? && !block_given?
|
|
89
|
-
Request
|
|
90
|
-
else
|
|
91
|
-
Request.with(options, &block)
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
# Set the field which records when a version was created.
|
|
96
|
-
# @api public
|
|
97
|
-
def timestamp_field=(_field_name)
|
|
98
|
-
raise(E_TIMESTAMP_FIELD_CONFIG)
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
# Set the PaperTrail serializer. This setting affects all threads.
|
|
102
|
-
# @api public
|
|
103
|
-
def serializer=(value)
|
|
104
|
-
PaperTrail.config.serializer = value
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
# Get the PaperTrail serializer used by all threads.
|
|
108
|
-
# @api public
|
|
109
|
-
def serializer
|
|
110
|
-
PaperTrail.config.serializer
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
# Returns PaperTrail's global configuration object, a singleton. These
|
|
114
|
-
# settings affect all threads.
|
|
115
|
-
# @api private
|
|
116
|
-
def config
|
|
117
|
-
@config ||= PaperTrail::Config.instance
|
|
118
|
-
yield @config if block_given?
|
|
119
|
-
@config
|
|
120
|
-
end
|
|
121
|
-
alias configure config
|
|
122
|
-
|
|
123
|
-
def version
|
|
124
|
-
VERSION::STRING
|
|
125
|
-
end
|
|
126
|
-
end
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
# We use the `on_load` "hook" instead of `ActiveRecord::Base.include` because we
|
|
130
|
-
# don't want to cause all of AR to be autloaded yet. See
|
|
131
|
-
# https://guides.rubyonrails.org/engines.html#what-are-on-load-hooks-questionmark
|
|
132
|
-
# to learn more about `on_load`.
|
|
133
16
|
ActiveSupport.on_load(:active_record) do
|
|
134
|
-
|
|
135
|
-
require "mongo_trails/mongo_support/version"
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
# require "mongo_trails/mongo_support/config"
|
|
139
|
-
|
|
140
|
-
# Require frameworks
|
|
141
|
-
if defined?(::Rails)
|
|
142
|
-
# Rails module is sometimes defined by gems like rails-html-sanitizer
|
|
143
|
-
# so we check for presence of Rails.application.
|
|
144
|
-
|
|
145
|
-
if defined?(::Rails.application)
|
|
146
|
-
require "mongo_trails/frameworks/rails"
|
|
147
|
-
else
|
|
148
|
-
::Kernel.warn(::PaperTrail::E_RAILS_NOT_LOADED)
|
|
149
|
-
end
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
if defined?(::ActiveRecord)
|
|
153
|
-
::PaperTrail::Compatibility.check_activerecord(::ActiveRecord.gem_version)
|
|
17
|
+
require 'mongo_trails/mongo_support/version'
|
|
154
18
|
end
|
data/mongo_trails.gemspec
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
$LOAD_PATH.unshift File.expand_path(
|
|
4
|
-
|
|
5
|
-
require "mongo_trails/compatibility"
|
|
6
|
-
require "mongo_trails/version_number"
|
|
3
|
+
$LOAD_PATH.unshift File.expand_path('lib', __dir__)
|
|
4
|
+
require 'mongo_trails/version'
|
|
7
5
|
|
|
8
6
|
Gem::Specification.new do |s|
|
|
9
|
-
s.name =
|
|
10
|
-
s.version =
|
|
7
|
+
s.name = 'mongo_trails'
|
|
8
|
+
s.version = MongoTrails::VERSION
|
|
11
9
|
s.platform = Gem::Platform::RUBY
|
|
12
|
-
s.summary =
|
|
13
|
-
s.description =
|
|
14
|
-
PaperTrail
|
|
15
|
-
|
|
16
|
-
s.homepage =
|
|
10
|
+
s.summary = 'PaperTrail addon to store versions in MongoDB'
|
|
11
|
+
s.description = <<~DSC
|
|
12
|
+
PaperTrail addon to store versions in MongoDB
|
|
13
|
+
DSC
|
|
14
|
+
s.homepage = 'https://github.com/noma4i/mongo_trails'
|
|
17
15
|
s.metadata['homepage_uri'] = s.homepage
|
|
18
16
|
s.metadata['source_code_uri'] = s.homepage
|
|
19
|
-
s.
|
|
20
|
-
s.
|
|
21
|
-
s.
|
|
17
|
+
s.metadata['allowed_push_host'] = 'https://rubygems.org'
|
|
18
|
+
s.metadata['rubygems_mfa_required'] = 'true'
|
|
19
|
+
s.authors = ['Alex Tsirel', 'Ivan Romanyuk']
|
|
20
|
+
s.email = ['noma4i@gmail.com']
|
|
21
|
+
s.license = 'MIT'
|
|
22
22
|
|
|
23
23
|
s.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
24
24
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
@@ -28,11 +28,10 @@ PaperTrail DropIn replacement to store version in MongoDB
|
|
|
28
28
|
s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
29
29
|
s.require_paths = ['lib']
|
|
30
30
|
|
|
31
|
-
s.add_dependency
|
|
32
|
-
s.add_dependency
|
|
33
|
-
s.add_dependency
|
|
34
|
-
s.add_dependency
|
|
31
|
+
s.add_dependency 'mongoid', '>= 7', '< 10'
|
|
32
|
+
s.add_dependency 'ostruct'
|
|
33
|
+
s.add_dependency 'paper_trail', '~> 16'
|
|
34
|
+
s.add_dependency 'sidekiq', '>= 6.5', '< 9'
|
|
35
35
|
|
|
36
|
-
s.
|
|
37
|
-
s.add_development_dependency 'appraisal', '~> 2.3'
|
|
36
|
+
s.required_ruby_version = '>= 3.2'
|
|
38
37
|
end
|