mongo_trails 10.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/.gitattributes +2 -0
  3. data/.gitignore +1 -0
  4. data/.travis.yml +13 -0
  5. data/Appraisals +7 -0
  6. data/Gemfile +7 -0
  7. data/Gemfile.lock +62 -0
  8. data/LICENSE +20 -0
  9. data/README.md +36 -0
  10. data/Rakefile +13 -0
  11. data/gemfiles/rails_5.gemfile +9 -0
  12. data/gemfiles/rails_5.gemfile.lock +63 -0
  13. data/gemfiles/rails_6.gemfile +9 -0
  14. data/gemfiles/rails_6.gemfile.lock +63 -0
  15. data/lib/mongo_trails.rb +154 -0
  16. data/lib/mongo_trails/attribute_serializers/README.md +10 -0
  17. data/lib/mongo_trails/attribute_serializers/attribute_serializer_factory.rb +27 -0
  18. data/lib/mongo_trails/attribute_serializers/cast_attribute_serializer.rb +51 -0
  19. data/lib/mongo_trails/attribute_serializers/object_attribute.rb +41 -0
  20. data/lib/mongo_trails/attribute_serializers/object_changes_attribute.rb +44 -0
  21. data/lib/mongo_trails/cleaner.rb +60 -0
  22. data/lib/mongo_trails/compatibility.rb +51 -0
  23. data/lib/mongo_trails/config.rb +41 -0
  24. data/lib/mongo_trails/events/base.rb +323 -0
  25. data/lib/mongo_trails/events/create.rb +32 -0
  26. data/lib/mongo_trails/events/destroy.rb +42 -0
  27. data/lib/mongo_trails/events/update.rb +60 -0
  28. data/lib/mongo_trails/frameworks/cucumber.rb +33 -0
  29. data/lib/mongo_trails/frameworks/rails.rb +4 -0
  30. data/lib/mongo_trails/frameworks/rails/controller.rb +109 -0
  31. data/lib/mongo_trails/frameworks/rails/engine.rb +43 -0
  32. data/lib/mongo_trails/frameworks/rspec.rb +43 -0
  33. data/lib/mongo_trails/frameworks/rspec/helpers.rb +29 -0
  34. data/lib/mongo_trails/has_paper_trail.rb +86 -0
  35. data/lib/mongo_trails/model_config.rb +249 -0
  36. data/lib/mongo_trails/mongo_support/config.rb +9 -0
  37. data/lib/mongo_trails/mongo_support/version.rb +56 -0
  38. data/lib/mongo_trails/queries/versions/where_object.rb +65 -0
  39. data/lib/mongo_trails/queries/versions/where_object_changes.rb +75 -0
  40. data/lib/mongo_trails/record_history.rb +51 -0
  41. data/lib/mongo_trails/record_trail.rb +304 -0
  42. data/lib/mongo_trails/reifier.rb +130 -0
  43. data/lib/mongo_trails/request.rb +166 -0
  44. data/lib/mongo_trails/serializers/json.rb +46 -0
  45. data/lib/mongo_trails/serializers/yaml.rb +43 -0
  46. data/lib/mongo_trails/type_serializers/postgres_array_serializer.rb +48 -0
  47. data/lib/mongo_trails/version_concern.rb +336 -0
  48. data/lib/mongo_trails/version_number.rb +23 -0
  49. data/mongo_trails.gemspec +38 -0
  50. metadata +180 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: fd695a8c38f1f2ec059a599f9e0988202be453d255a342bd311f8843ad891fd4
4
+ data.tar.gz: 4e5fad1e481370cebb42c93059217f4ca360f72c8c93ae78ef36943298226b3c
5
+ SHA512:
6
+ metadata.gz: 81ddc616e9b0c1f39cdb43ff864df07b220c0ec8fb375bd3f6dea71df560e7e015e57b2579c3e4d1dbe1ed261f00f602823c6445ed0525c867a95218f3f3dadc
7
+ data.tar.gz: 38e4dc6710b075b1531d1073b6d7b019877e46e9c6430138414b84a19f8abd47229237dd766bb49411a1e1c902e3dd57a3f71b1fdc35b9a8fb16c1fa37c56fab
@@ -0,0 +1,2 @@
1
+ # Auto detect text files and perform LF normalization
2
+ * text=auto
@@ -0,0 +1 @@
1
+ *.gem
@@ -0,0 +1,13 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.5.3
6
+ before_install: gem install bundler -v 2.1.4
7
+ gemfile:
8
+ - gemfiles/rails_5.gemfile
9
+ - gemfiles/rails_6.gemfile
10
+
11
+ services: mongodb
12
+
13
+ script: 'bundle exec rake test'
@@ -0,0 +1,7 @@
1
+ appraise 'rails-5' do
2
+ gem 'activerecord', '~> 5.0'
3
+ end
4
+
5
+ appraise 'rails-6' do
6
+ gem 'activerecord', '~> 6.0'
7
+ end
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ar_shard.gemspec
4
+ gemspec
5
+
6
+ gem 'rake', '~> 12.0'
7
+ gem 'minitest', '~> 5.0'
@@ -0,0 +1,62 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mongo_trails (10.3.1)
5
+ activerecord (>= 5.2)
6
+ mongoid (< 8)
7
+ mongoid-autoinc (< 7)
8
+ request_store (~> 1.1)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ activemodel (6.0.3.2)
14
+ activesupport (= 6.0.3.2)
15
+ activerecord (6.0.3.2)
16
+ activemodel (= 6.0.3.2)
17
+ activesupport (= 6.0.3.2)
18
+ activesupport (6.0.3.2)
19
+ concurrent-ruby (~> 1.0, >= 1.0.2)
20
+ i18n (>= 0.7, < 2)
21
+ minitest (~> 5.1)
22
+ tzinfo (~> 1.1)
23
+ zeitwerk (~> 2.2, >= 2.2.2)
24
+ appraisal (2.3.0)
25
+ bundler
26
+ rake
27
+ thor (>= 0.14.0)
28
+ bson (4.10.0)
29
+ concurrent-ruby (1.1.7)
30
+ i18n (1.8.5)
31
+ concurrent-ruby (~> 1.0)
32
+ minitest (5.14.1)
33
+ mongo (2.13.0)
34
+ bson (>= 4.8.2, < 5.0.0)
35
+ mongoid (7.1.2)
36
+ activemodel (>= 5.1, < 6.1)
37
+ mongo (>= 2.7.0, < 3.0.0)
38
+ mongoid-autoinc (6.0.3)
39
+ mongoid (>= 6.0, < 8.0)
40
+ rack (2.2.3)
41
+ rake (12.3.3)
42
+ request_store (1.5.0)
43
+ rack (>= 1.4)
44
+ sqlite3 (1.4.2)
45
+ thor (1.0.1)
46
+ thread_safe (0.3.6)
47
+ tzinfo (1.2.7)
48
+ thread_safe (~> 0.1)
49
+ zeitwerk (2.4.0)
50
+
51
+ PLATFORMS
52
+ ruby
53
+
54
+ DEPENDENCIES
55
+ appraisal (~> 2.3)
56
+ minitest (~> 5.0)
57
+ mongo_trails!
58
+ rake (~> 12.0)
59
+ sqlite3 (~> 1.4)
60
+
61
+ BUNDLED WITH
62
+ 1.17.3
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Andy Stewart, AirBlade Software Ltd.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,36 @@
1
+ [![Build Status](https://travis-ci.com/noma4i/mongo_trails.svg?branch=master)](https://travis-ci.com/noma4i/mongo_trails)
2
+
3
+ # PaperTrail to MongoDB storage
4
+
5
+ Based on paper-trail gem `v10.3.1`. All future versions will follow version of the parent Paper Trail gem
6
+
7
+ Track changes to your models, for auditing or versioning. See how a model looked
8
+ at any stage in its lifecycle, revert it to any version, or restore it after it
9
+ has been destroyed.
10
+
11
+ ## How to Use
12
+
13
+ Add to Gemfile
14
+
15
+ ```ruby
16
+ gem 'mongo-trail', git: 'https://github.com/noma4i/mongo_trails'
17
+ ```
18
+
19
+ Create initializer like:
20
+
21
+ ```ruby
22
+ PaperTrail.config.mongo_config = { hosts: ['localhost:27017'], database: 'my_test_db' }
23
+ PaperTrail.config.mongo_prefix = lambda do
24
+ 'my_cool_prefix'
25
+ end
26
+
27
+ require 'mongo_trails/mongo_support/config'
28
+ ```
29
+
30
+ Done!
31
+
32
+ ## Using Rspec
33
+
34
+ `require 'mongo_trails/frameworks/rspec'`
35
+
36
+ API is the same as `paper_trail`
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'test'
8
+ t.libs << 'lib'
9
+ t.test_files = FileList['test/**/*_test.rb']
10
+ end
11
+
12
+ task default: :test
13
+
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rake", "~> 12.0"
6
+ gem "minitest", "~> 5.0"
7
+ gem "activerecord", "~> 5.0"
8
+
9
+ gemspec path: "../"
@@ -0,0 +1,63 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ mongo_trails (10.3.1)
5
+ activerecord (>= 5.2)
6
+ mongoid (< 8)
7
+ mongoid-autoinc (< 7)
8
+ request_store (~> 1.1)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ activemodel (5.2.4.3)
14
+ activesupport (= 5.2.4.3)
15
+ activerecord (5.2.4.3)
16
+ activemodel (= 5.2.4.3)
17
+ activesupport (= 5.2.4.3)
18
+ arel (>= 9.0)
19
+ activesupport (5.2.4.3)
20
+ concurrent-ruby (~> 1.0, >= 1.0.2)
21
+ i18n (>= 0.7, < 2)
22
+ minitest (~> 5.1)
23
+ tzinfo (~> 1.1)
24
+ appraisal (2.3.0)
25
+ bundler
26
+ rake
27
+ thor (>= 0.14.0)
28
+ arel (9.0.0)
29
+ bson (4.10.0)
30
+ concurrent-ruby (1.1.7)
31
+ i18n (1.8.5)
32
+ concurrent-ruby (~> 1.0)
33
+ minitest (5.14.1)
34
+ mongo (2.13.0)
35
+ bson (>= 4.8.2, < 5.0.0)
36
+ mongoid (7.1.2)
37
+ activemodel (>= 5.1, < 6.1)
38
+ mongo (>= 2.7.0, < 3.0.0)
39
+ mongoid-autoinc (6.0.3)
40
+ mongoid (>= 6.0, < 8.0)
41
+ rack (2.2.3)
42
+ rake (12.3.3)
43
+ request_store (1.5.0)
44
+ rack (>= 1.4)
45
+ sqlite3 (1.4.2)
46
+ thor (1.0.1)
47
+ thread_safe (0.3.6)
48
+ tzinfo (1.2.7)
49
+ thread_safe (~> 0.1)
50
+
51
+ PLATFORMS
52
+ ruby
53
+
54
+ DEPENDENCIES
55
+ activerecord (~> 5.0)
56
+ appraisal (~> 2.3)
57
+ minitest (~> 5.0)
58
+ mongo_trails!
59
+ rake (~> 12.0)
60
+ sqlite3 (~> 1.4)
61
+
62
+ BUNDLED WITH
63
+ 1.17.3
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rake", "~> 12.0"
6
+ gem "minitest", "~> 5.0"
7
+ gem "activerecord", "~> 6.0"
8
+
9
+ gemspec path: "../"
@@ -0,0 +1,63 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ mongo_trails (10.3.1)
5
+ activerecord (>= 5.2)
6
+ mongoid (< 8)
7
+ mongoid-autoinc (< 7)
8
+ request_store (~> 1.1)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ activemodel (6.0.3.2)
14
+ activesupport (= 6.0.3.2)
15
+ activerecord (6.0.3.2)
16
+ activemodel (= 6.0.3.2)
17
+ activesupport (= 6.0.3.2)
18
+ activesupport (6.0.3.2)
19
+ concurrent-ruby (~> 1.0, >= 1.0.2)
20
+ i18n (>= 0.7, < 2)
21
+ minitest (~> 5.1)
22
+ tzinfo (~> 1.1)
23
+ zeitwerk (~> 2.2, >= 2.2.2)
24
+ appraisal (2.3.0)
25
+ bundler
26
+ rake
27
+ thor (>= 0.14.0)
28
+ bson (4.10.0)
29
+ concurrent-ruby (1.1.7)
30
+ i18n (1.8.5)
31
+ concurrent-ruby (~> 1.0)
32
+ minitest (5.14.1)
33
+ mongo (2.13.0)
34
+ bson (>= 4.8.2, < 5.0.0)
35
+ mongoid (7.1.2)
36
+ activemodel (>= 5.1, < 6.1)
37
+ mongo (>= 2.7.0, < 3.0.0)
38
+ mongoid-autoinc (6.0.3)
39
+ mongoid (>= 6.0, < 8.0)
40
+ rack (2.2.3)
41
+ rake (12.3.3)
42
+ request_store (1.5.0)
43
+ rack (>= 1.4)
44
+ sqlite3 (1.4.2)
45
+ thor (1.0.1)
46
+ thread_safe (0.3.6)
47
+ tzinfo (1.2.7)
48
+ thread_safe (~> 0.1)
49
+ zeitwerk (2.4.0)
50
+
51
+ PLATFORMS
52
+ ruby
53
+
54
+ DEPENDENCIES
55
+ activerecord (~> 6.0)
56
+ appraisal (~> 2.3)
57
+ minitest (~> 5.0)
58
+ mongo_trails!
59
+ rake (~> 12.0)
60
+ sqlite3 (~> 1.4)
61
+
62
+ BUNDLED WITH
63
+ 1.17.3
@@ -0,0 +1,154 @@
1
+ # frozen_string_literal: true
2
+
3
+ # AR does not require all of AS, but PT does. PT uses core_ext like
4
+ # `String#squish`, so we require `active_support/all`. Instead of eagerly
5
+ # loading all of AS here, we could put specific `require`s in only the various
6
+ # PT files that need them, but this seems easier to troubleshoot, though it may
7
+ # add a few milliseconds to rails boot time. If that becomes a pain point, we
8
+ # can revisit this decision.
9
+ require "active_support/all"
10
+
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
+ ActiveSupport.on_load(:active_record) do
134
+ include PaperTrail::Model
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)
154
+ end