paper_trail-actor 0.4.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5feb0e3bd1d5d354acc67d9da8ce59737cd5f9d2003aac8a06d6d97abe9a964d
4
+ data.tar.gz: 4c539f383eff32c652da404f3bf8edcc215cf3e1b1357b6d1566d0ad8abc37c0
5
+ SHA512:
6
+ metadata.gz: 396ac19a6b0ec27b2bddbc46c58e34819d6a1761fc2acee5cff4b3e9143b939c3a0f0dda67c4463d8581d44ef9fbc79ba492326ba8d66ba2c0cb8e5e2ca357ce
7
+ data.tar.gz: e8077674949aa3d963b543d74c495edb6ccf975fb86821c8dc97ecc9db0527702ca5f412ee28b12849b8edf2701319cf89dee9dc3354415ffc9830ed46cf5912
data/CHANGELOG.md ADDED
@@ -0,0 +1,54 @@
1
+ ## [Unreleased]
2
+
3
+ - This gem was forked from [paper_trail-globalid](https://github.com/ankit1910/paper_trail-globalid) where the last release was version 0.2.0.
4
+
5
+ ### Breaking Changes
6
+
7
+ - None
8
+
9
+ ### Added
10
+
11
+ - None
12
+
13
+ ### Fixed
14
+
15
+ - None
16
+
17
+ ## [0.3.0] - 2025-04-11
18
+
19
+ - Bring fixes in and allow updated gem to be installed from GitHub.
20
+
21
+ ### Breaking Changes
22
+
23
+ - Only work with PaperTrail >= 9.0.0 as that is the interface that we now use.
24
+ Not all monkey patched classes exist in earlier versions.
25
+
26
+ ### Added
27
+
28
+ - None
29
+
30
+ ### Fixed
31
+
32
+ - [#1](https://github.com/tttffff/paper_trail-actor/pull/1) - Update to modern paper_trail.
33
+ Update to use the interface of PaperTrail 9.0.0 onwards.
34
+ - [#2](https://github.com/tttffff/paper_trail-actor/pull/2) - Allow for using custom paper trail version classes.
35
+ Change version mixin to allow for PaperTrail [custom-version-classes](https://github.com/paper-trail-gem/paper_trail#6a-custom-version-classes).
36
+
37
+
38
+ ## [0.4.0] - 2025-04-20
39
+
40
+ - Initial release of paper_trail-actor
41
+
42
+ ### Breaking Changes
43
+
44
+ - Only support PaperTrail >= 11.0.0.
45
+ While this gem will technically work with versions >= 9.0.0, it is more complex to test for versions less than 11.0.0.
46
+ As 11.0.0 is from 2020, there is no need to test or support any earlier versions.
47
+
48
+ ### Added
49
+
50
+ - None
51
+
52
+ ### Fixed
53
+
54
+ - None
data/LICENSE.txt ADDED
@@ -0,0 +1,25 @@
1
+ Copyright (c) 2016 ankit1910
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ # Additional Copyright Holders:
25
+ Copyright (c) 2025 tttffff
data/README.md ADDED
@@ -0,0 +1,82 @@
1
+ # PaperTrail-Actor
2
+
3
+ Originally forked from the now unmaintained [paper_trail-globalid](https://github.com/ankit1910/paper_trail-globalid).
4
+
5
+ This gem is an extension to the [PaperTrail](https://github.com/paper-trail-gem/paper_trail) gem.
6
+
7
+ - Allows setting an `ActiveRecord` object for the whodunnit field on the PaperTrail request object and version objects.
8
+ - Adds the method `#actor` to the PaperTrail request object which returns the `ActiveRecord` object that will be responsible for subsequent changes.
9
+ - Adds the method `#actor` to PaperTrail version objects which returns the `ActiveRecord` object that was responsible for change.
10
+
11
+ ## Installation
12
+
13
+ 1. Add PaperTrail-Actor to your `Gemfile`.
14
+ ```ruby
15
+ gem "paper_trail-actor"
16
+ ```
17
+ 2. And then execute:
18
+ ```sh
19
+ bundle install
20
+ ```
21
+
22
+ ## Basic Usage
23
+
24
+ This gem works by storing the [globalid](https://github.com/rails/globalid) to the whodunnit field of PaperTrail version tables.
25
+ - It is designed not to hinder or break existing PaperTrail functionalities.
26
+ - PaperTrail versions with and without a globalid can live side by side (e.g. versions created before installing this gem.)
27
+
28
+ ```ruby
29
+ product = Product.find(42)
30
+ admin = Admin.find(1) # <Admin:0x007fa2df9a5590>
31
+
32
+ PaperTrail.request.whodunnit = admin
33
+ PaperTrail.request.whodunnit # "gid://app/Admin/1"
34
+ PaperTrail.request.actor # <Admin:0x007fa2df9a5590> returns the actual object
35
+
36
+ product.update(name: "Ice cream")
37
+ product.versions.last.whodunnit # "gid://app/Admin/1"
38
+ product.versions.last.actor # <Admin:0x007fa2df9a5590> returns the actual object
39
+ ```
40
+
41
+ ### Setting whodunnit to something other than an ActiveRecord object
42
+
43
+ You can continue to set whodunnit to something other than an `ActiveRecord` object.
44
+ - It follows standard PaperTrail functionality and adds the raw value to the whodunnit field.
45
+ - The `#actor` method will return the raw value.
46
+
47
+ ```ruby
48
+ PaperTrail.request.whodunnit = "Alex the admin"
49
+ PaperTrail.request.whodunnit # "Alex the admin"
50
+ PaperTrail.request.actor # "Alex the admin"
51
+
52
+ product.update(name: "99 Flake")
53
+ product.versions.last.whodunnit # "Alex the admin"
54
+ product.versions.last.actor # "Alex the admin"
55
+ ```
56
+
57
+ ### Updating whodunnit on existing PaperTrail versions
58
+
59
+ You can retrospectivly update PaperTrail versions to have a new actor.
60
+
61
+ ```ruby
62
+ most_recent_product_version = product.versions.last
63
+ admin_name = most_recent_product_version.actor # "Alex the admin"
64
+ alex_the_admin = Admin.find_by(name: admin_name) # Do check for `nil` before updating the whodunit field
65
+ most_recent_product_version.whodunnit = alex_the_admin
66
+ most_recent_product_version.save
67
+ most_recent_product_version.actor # <Admin:0x00000120fbb7d0>
68
+ ```
69
+
70
+ ### Setting whodunnit with a controller callback
71
+
72
+ Similar to how you can configure the PaperTrail gem, as described in [Setting Whodunnit with a Controller Callback](https://github.com/paper-trail-gem/paper_trail/?tab=readme-ov-file#setting-whodunnit-with-a-controller-callback), you can now set this to an ActiveRecord object. This allows storing the global ID and retrieving the actor using the `#actor` methods.
73
+
74
+ Here’s an example in your `ApplicationController`:
75
+
76
+ ```ruby
77
+ class ApplicationController < ActionController::Base
78
+ def user_for_paper_trail
79
+ logged_in? ? current_user : "Public user"
80
+ end
81
+ end
82
+ ```
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ require "standard/rake"
7
+
8
+ task default: %i[spec standard]
@@ -0,0 +1,15 @@
1
+ module PaperTrailActor
2
+ module Request
3
+ def whodunnit=(value)
4
+ if value.is_a? ActiveRecord::Base
5
+ super(value.to_gid)
6
+ else
7
+ super
8
+ end
9
+ end
10
+
11
+ def actor
12
+ ::GlobalID::Locator.locate(store[:whodunnit]) || whodunnit
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module PaperTrailActor
2
+ VERSION = "0.4.0"
3
+ end
@@ -0,0 +1,20 @@
1
+ module PaperTrailActor
2
+ module VersionConcern
3
+ def whodunnit=(input_value)
4
+ whodunnit_value = if input_value.is_a?(ActiveRecord::Base)
5
+ input_value.to_gid
6
+ else
7
+ input_value
8
+ end
9
+ _write_attribute("whodunnit", whodunnit_value)
10
+ end
11
+
12
+ # Returns an object which was responsible for a change
13
+ # you need to store global_id to whodunnit field to make this method return the object(who was responsible)
14
+ # for example, whodunnit => "gid://app/Order/1" then
15
+ # whodunnit_user will return Order.find_by(id: 1) in application scope.
16
+ def actor
17
+ ::GlobalID::Locator.locate(whodunnit) || whodunnit
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ require "paper_trail-actor/version"
2
+ require "paper_trail-actor/request"
3
+ require "paper_trail-actor/version_concern"
4
+
5
+ module ::PaperTrail
6
+ module Request
7
+ class << self
8
+ prepend ::PaperTrailActor::Request
9
+ end
10
+ end
11
+ end
12
+
13
+ module ::PaperTrail
14
+ module VersionConcern
15
+ include ::PaperTrailActor::VersionConcern
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,182 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: paper_trail-actor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ platform: ruby
6
+ authors:
7
+ - tttffff
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-04-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: paper_trail
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 11.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 11.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: globalid
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: activerecord
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: activesupport
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: sqlite3
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: byebug
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: standard
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: An extension to PaperTrail. Using this gem, you can fetch the ActiveRecord
140
+ object that was responsible for changes
141
+ email:
142
+ - tristanfellows@icloud.com
143
+ executables: []
144
+ extensions: []
145
+ extra_rdoc_files: []
146
+ files:
147
+ - CHANGELOG.md
148
+ - LICENSE.txt
149
+ - README.md
150
+ - Rakefile
151
+ - lib/paper_trail-actor.rb
152
+ - lib/paper_trail-actor/request.rb
153
+ - lib/paper_trail-actor/version.rb
154
+ - lib/paper_trail-actor/version_concern.rb
155
+ homepage: https://github.com/tttffff/paper_trail-actor
156
+ licenses:
157
+ - MIT
158
+ metadata:
159
+ homepage_uri: https://github.com/tttffff/paper_trail-actor
160
+ source_code_uri: https://github.com/tttffff/paper_trail-actor
161
+ changelog_uri: https://github.com/tttffff/paper_trail-actor/blob/master/CHANGELOG.md
162
+ post_install_message:
163
+ rdoc_options: []
164
+ require_paths:
165
+ - lib
166
+ required_ruby_version: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ required_rubygems_version: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - ">="
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ requirements: []
177
+ rubygems_version: 3.5.22
178
+ signing_key:
179
+ specification_version: 4
180
+ summary: An extension to PaperTrail. Using this gem, you can fetch the ActiveRecord
181
+ object that was responsible for changes
182
+ test_files: []