2
2
3
3
## Overview
4
4
5
- Userstamp extends ` ActiveRecord::Base ` to add automatic updating of ` creator ` , ` updater ` , and
5
+ Userstamp extends ` ActiveRecord::Base ` to add automatic updating of ` creator ` , ` updater ` , and
6
6
` deleter ` attributes. It is based loosely on ` ActiveRecord::Timestamp ` .
7
7
8
8
Two class methods (` model_stamper ` and ` stampable ` ) are implemented in this gem. The ` model_stamper `
9
9
method is used in models that are responsible for creating, updating, or deleting other objects.
10
- Typically this would be the ` User ` model of your application. The ` stampable ` method is used in
10
+ Typically this would be the ` User ` model of your application. The ` stampable ` method is used in
11
11
models that are subject to being created, updated, or deleted by stampers.
12
12
13
13
## Forkception
14
14
15
15
This is a fork of:
16
16
17
- - the [ magiclabs-userstamp] ( https://github.com/magiclabs/userstamp ) gem
18
- - which is a fork of [ Michael Grosser's] ( https://github.com/grosser )
19
- [ userstamp gem] (https://github.com/grosser/userstamp )
20
- - which is a fork of the original [ userstamp plugin] ( https://github.com/delynn/userstamp ) by
21
- [ delynn] ( https://github.com/delynn )
17
+ - the [ magiclabs-userstamp] ( https://github.com/magiclabs/userstamp ) gem
18
+ - which is a fork of [ Michael Grosser's] ( https://github.com/grosser )
19
+ [ userstamp gem] (https://github.com/grosser/userstamp )
20
+ - which is a fork of the original [ userstamp plugin] ( https://github.com/delynn/userstamp ) by
21
+ [ delynn] ( https://github.com/delynn )
22
22
23
23
In addition to these, I have cherry picked ideas and changes from the following forks:
24
24
25
- - [ simplificator] ( https://github.com/simplificator/userstamp )
26
- - [ akm] ( https://github.com/akm/magic_userstamp )
27
- - [ konvenit] ( https://github.com/konvenit/userstamp )
25
+ - [ simplificator] ( https://github.com/simplificator/userstamp )
26
+ - [ akm] ( https://github.com/akm/magic_userstamp )
27
+ - [ konvenit] ( https://github.com/konvenit/userstamp )
28
28
29
- Finally, this gem only supports Ruby 2.0 and above. Yes, you really should upgrade to a supported
30
- version of Ruby. This gem is tested only on Rails 4.2; but it should work with Rails 4+.
29
+ Finally, this gem only supports Ruby 3.0 and 3.1. Yes, you really should upgrade to a supported
30
+ version of Ruby. This gem is tested only on Rails 6 - 7; thus far, we have successfully tested it
31
+ to be compatible with Rails 6.0, 6.1, 7.0, and 7.1
31
32
32
33
## Features
34
+
33
35
### Soft-deletes
36
+
34
37
The reason for this is because the original userstamp plugin does not support databases utilising
35
38
soft deletes. They are not tested explicitly within this gem, but it is expected to work with the
36
39
following gems:
37
40
38
- - [ acts_as_paranoid] ( https://github.com/ActsAsParanoid/acts_as_paranoid )
39
- - [ paranoia] ( https://github.com/radar/paranoia )
41
+ - [ acts_as_paranoid] ( https://github.com/ActsAsParanoid/acts_as_paranoid )
42
+ - [ paranoia] ( https://github.com/radar/paranoia )
40
43
41
- The ` stampable ` method has been modified to allow additional arguments to be passed to the
44
+ The ` stampable ` method has been modified to allow additional arguments to be passed to the
42
45
creator/updater relations. This allows declarations like:
43
46
44
47
``` ruby
@@ -51,16 +54,18 @@ to result in a `belongs_to` relation which looks like:
51
54
belongs_to :creator , class_name: ' ::User' , foreign_key: :created_by , with_deleted: true
52
55
```
53
56
54
- Do create a ticket if it is broken, with a pull-request if possible.
57
+ Do create a ticket if it is broken, with a pull-request if possible.
55
58
56
59
### Customisable column names/types
60
+
57
61
While examining the userstamp gem's network on Github, it was noticed that quite a few forks were
58
62
made to allow customisability in the name and type of the column with the database migration.
59
63
60
64
This gem now supports customised column names. See the [ usage] ( #usage ) section on the
61
65
configuration options supported.
62
66
63
67
### Saving before validation
68
+
64
69
This fork includes changes to perform model stamping before validation. This allows models to
65
70
enforce the presence of stamp attributes:
66
71
@@ -73,7 +78,8 @@ Furthermore, the `creator` attribute is set only if the value is blank allowing
73
78
override.
74
79
75
80
## Usage
76
- Assume that we are building a blog application, with User and Post objects. Add the following
81
+
82
+ Assume that we are building a blog application, with User and Post objects. Add the following
77
83
to the application's Gemfile:
78
84
79
85
``` ruby
@@ -135,9 +141,10 @@ Declare the stamper on the User model:
135
141
If your stamper is called ` User ` , that's it; you're done.
136
142
137
143
## Customisation
144
+
138
145
The association which is created on each of the ` creator_id ` , ` updater_id ` , and ` deleter_id ` can
139
146
be customised. Also, the stamper used by each class can also be customised. For this purpose, the
140
- ` ActiveRecord::Base.stampable ` method can be used:
147
+ ` ActiveRecord::Base.stampable ` method can be used:
141
148
142
149
``` ruby
143
150
class Post < ActiveRecord ::Base
@@ -150,8 +157,10 @@ It also allows you to specify the name of the stamper for the class being declar
150
157
arguments are passed to the ` belongs_to ` declaration.
151
158
152
159
## Upgrading
160
+
153
161
### Upgrading from delynn's 1.x/2.x with ` compatibility_mode `
154
- The major difference between 1.x and 2.x is the naming of the columns. This version of the gem
162
+
163
+ The major difference between 1.x and 2.x is the naming of the columns. This version of the gem
155
164
allows specifying the name of the column from the gem configuration:
156
165
157
166
``` ruby
163
172
```
164
173
165
174
### Upgrading from delynn's 2.x without ` compatibility_mode `
175
+
166
176
Within migrations, it was possible to declare ` t.userstamps ` within a table definition. It used
167
177
to accept one argument, which declares whether the deleter column should be created. This has
168
178
been changed to respect the gem configuration's ` deleter_attribute ` . If that is ` nil ` , then no
@@ -182,16 +192,18 @@ Configure the gem to use those names (as above) and remove all `stampable` decla
182
192
There is no need to include the ` Userstamp ` module in ` ApplicationController ` .
183
193
184
194
## Tests
195
+
185
196
Run
186
197
187
198
$ bundle exec rspec
188
199
189
200
## Authors
190
- - [ DeLynn Berry] ( http://delynnberry.com/ ) : The original idea for this plugin came from the Rails
191
- Wiki article entitled
192
- [ Extending ActiveRecord] ( http://wiki.rubyonrails.com/rails/pages/ExtendingActiveRecordExample )
193
- - [ Michael Grosser] ( http://pragmatig.com )
194
- - [ John Dell] ( http://blog.spovich.com/ )
195
- - [ Chris Hilton] ( https://github.com/chrismhilton )
196
- - [ Thomas von Deyen] ( https://github.com/tvdeyen )
197
- - [ Joel Low] ( http://joelsplace.sg )
201
+
202
+ - [ DeLynn Berry] ( http://delynnberry.com/ ) : The original idea for this plugin came from the Rails
203
+ Wiki article entitled
204
+ [ Extending ActiveRecord] ( http://wiki.rubyonrails.com/rails/pages/ExtendingActiveRecordExample )
205
+ - [ Michael Grosser] ( http://pragmatig.com )
206
+ - [ John Dell] ( http://blog.spovich.com/ )
207
+ - [ Chris Hilton] ( https://github.com/chrismhilton )
208
+ - [ Thomas von Deyen] ( https://github.com/tvdeyen )
209
+ - [ Joel Low] ( http://joelsplace.sg )
0 commit comments