userstamper 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +35 -0
  5. data/CHANGELOG.md +116 -0
  6. data/Gemfile +3 -0
  7. data/Gemfile.lock +222 -0
  8. data/LICENSE +22 -0
  9. data/README.md +142 -0
  10. data/lib/userstamper.rb +23 -0
  11. data/lib/userstamper/configuration.rb +40 -0
  12. data/lib/userstamper/controller_concern.rb +44 -0
  13. data/lib/userstamper/migration_concern.rb +9 -0
  14. data/lib/userstamper/model_concern.rb +6 -0
  15. data/lib/userstamper/railtie.rb +15 -0
  16. data/lib/userstamper/stampable.rb +106 -0
  17. data/lib/userstamper/stamper.rb +54 -0
  18. data/lib/userstamper/utilities.rb +57 -0
  19. data/spec/controllers/posts_controller_spec.rb +44 -0
  20. data/spec/controllers/users_controller_spec.rb +50 -0
  21. data/spec/coverage_helper.rb +58 -0
  22. data/spec/dummy/README.rdoc +28 -0
  23. data/spec/dummy/Rakefile +6 -0
  24. data/spec/dummy/app/assets/config/manifest.js +0 -0
  25. data/spec/dummy/app/assets/images/.keep +0 -0
  26. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  27. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  28. data/spec/dummy/app/controllers/application_controller.rb +13 -0
  29. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  30. data/spec/dummy/app/controllers/posts_controller.rb +36 -0
  31. data/spec/dummy/app/controllers/users_controller.rb +22 -0
  32. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  33. data/spec/dummy/app/mailers/.keep +0 -0
  34. data/spec/dummy/app/models/comment.rb +5 -0
  35. data/spec/dummy/app/models/concerns/.keep +0 -0
  36. data/spec/dummy/app/models/person.rb +3 -0
  37. data/spec/dummy/app/models/post.rb +6 -0
  38. data/spec/dummy/app/models/tag.rb +3 -0
  39. data/spec/dummy/app/models/user.rb +3 -0
  40. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  41. data/spec/dummy/bin/bundle +3 -0
  42. data/spec/dummy/bin/rails +4 -0
  43. data/spec/dummy/bin/rake +4 -0
  44. data/spec/dummy/bin/setup +29 -0
  45. data/spec/dummy/config.ru +4 -0
  46. data/spec/dummy/config/application.rb +12 -0
  47. data/spec/dummy/config/boot.rb +5 -0
  48. data/spec/dummy/config/database.yml +23 -0
  49. data/spec/dummy/config/environment.rb +5 -0
  50. data/spec/dummy/config/environments/development.rb +41 -0
  51. data/spec/dummy/config/environments/production.rb +79 -0
  52. data/spec/dummy/config/environments/test.rb +37 -0
  53. data/spec/dummy/config/initializers/assets.rb +11 -0
  54. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  55. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  56. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  57. data/spec/dummy/config/initializers/inflections.rb +16 -0
  58. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  59. data/spec/dummy/config/initializers/session_store.rb +3 -0
  60. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  61. data/spec/dummy/config/locales/en.yml +23 -0
  62. data/spec/dummy/config/routes.rb +56 -0
  63. data/spec/dummy/config/secrets.yml +22 -0
  64. data/spec/dummy/lib/assets/.keep +0 -0
  65. data/spec/dummy/log/.keep +0 -0
  66. data/spec/dummy/public/404.html +67 -0
  67. data/spec/dummy/public/422.html +67 -0
  68. data/spec/dummy/public/500.html +66 -0
  69. data/spec/dummy/public/favicon.ico +0 -0
  70. data/spec/lib/configuration_spec.rb +20 -0
  71. data/spec/lib/migration_spec.rb +60 -0
  72. data/spec/lib/stamper_spec.rb +66 -0
  73. data/spec/lib/stamping_spec.rb +235 -0
  74. data/spec/lib/userstamp_spec.rb +4 -0
  75. data/spec/rails_helper.rb +7 -0
  76. data/spec/spec_helper.rb +98 -0
  77. data/spec/support/database_helpers.rb +73 -0
  78. data/spec/support/with_temporary_table.rb +51 -0
  79. data/userstamper.gemspec +46 -0
  80. metadata +279 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 573cc10f10027aeabf2f04892ea63c517fed448bdea2f909c4f307d9123d1944
4
+ data.tar.gz: 62283d938f34afaedcc402efa5fdf2be2446c253fa55773094bf760fee4ea6c2
5
+ SHA512:
6
+ metadata.gz: c3c6dbfa08158b688a48d54f01c39c59e3fd487e83b393407d48990cc369fe2683fb18e2ecf08302487574d31944815cc33c8aa25042308b9b26adc4ac4816cf
7
+ data.tar.gz: d732dc019eb418216f9c0e0bfdfeb9c85b57103a8d3d3c878e24bd45b1dd3fe9ba756d86b3ca56a2ba76ca8bda1c4910226c3e37625578999e6258f83cdd61fc
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.log
2
+ *.sqlite3
3
+ /.rdoc
4
+ /spec/examples.txt
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,35 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.1.10
5
+ - 2.2.6
6
+ - 2.3.3
7
+ - 2.4.0
8
+ - ruby-head
9
+ env:
10
+ - "RAILS_VERSION=4.1.0"
11
+ - "RAILS_VERSION=4.2.0"
12
+ - "RAILS_VERSION=5.0.0"
13
+ matrix:
14
+ allow_failures:
15
+ - rvm: ruby-head
16
+ exclude:
17
+ - rvm: 2.1.10
18
+ env: "RAILS_VERSION=5.0.0"
19
+ - rvm: 2.4.0
20
+ env: "RAILS_VERSION=4.1.0"
21
+ - rvm: 2.4.0
22
+ env: "RAILS_VERSION=4.2.0"
23
+ - rvm: ruby-head
24
+ env: "RAILS_VERSION=4.1.0"
25
+ - rvm: ruby-head
26
+ env: "RAILS_VERSION=4.2.0"
27
+
28
+ bundler_args: "--jobs=3 --retry=3"
29
+ cache: bundler
30
+
31
+ before_install:
32
+ - gem update bundler
33
+
34
+ after_success:
35
+ - bundle exec codeclimate-test-reporter
data/CHANGELOG.md ADDED
@@ -0,0 +1,116 @@
1
+ # Changelog
2
+ ## 4.0.0 (09-04-2021)
3
+ * Priit Tark - Rails 6.1 support and renamed gem to userstamper
4
+
5
+ ## 3.0.5 (22-8-2017)
6
+ * Jonathan Putney - Support Rails 5.0.
7
+ * Joel Low - Add additional combinations to Travis build matrix.
8
+ * Joel Low - Defer association definitions until the schema is loaded.
9
+ * Joel Low - Respect custom stamper definitions.
10
+
11
+ ## 3.0.4 (14-7-2015)
12
+ * Joel Low - Allow using ActiveRecord-Userstamp with anonymous models (e.g. some
13
+ `has_and_belongs_to_many` join tables.)
14
+
15
+ ## 3.0.3 (14-7-2015)
16
+ * Joel Low - Allow using ActiveRecord-Userstamp with generated tables (e.g.
17
+ `has_and_belongs_to_many` join tables.)
18
+
19
+ ## 3.0.2 (12-7-2015)
20
+ * Joel Low - Depending on what was set to a stamper (ID or record object), the
21
+ association ID or association setter is used to assign the
22
+ creator/updater/deleter attributes. This only applies if the attributes
23
+ end with `_id`; otherwise the attribute would be used verbatim (e.g. the
24
+ compatibility mode `created_by`).
25
+ * Joel Low - Provide a `with_stamper` method to specify the stamper for a given
26
+ stamper class during the execution of the block.
27
+ * Joel Low - Ensure that the `set_stamper` and `reset_stamper` calls from the
28
+ controller are always paired so that the stamper state is always properly
29
+ restored. `set_stamper` and `reset_stamper` is now deprecated and will be
30
+ removed in ActiveRecord::Userstamp 3.1 and replaced with a single
31
+ `with_stamper` `around_action` callback.
32
+
33
+ ## 3.0.1 (11-7-2015)
34
+ * Joel Low - Only declare the creator/updater/deleter associations when the table has
35
+ the attribute columns. If the columns cannot be determined (e.g. if the
36
+ table has not been defined, such as during tests), then the model would
37
+ need to explicitly call `stampable`.
38
+
39
+ ## 3.0.0 (10-7-2015)
40
+ * Joel Low - Remove `compatibility_mode`. Use the `creator_attribute`,
41
+ `updater_attribute`, and `deleter_attribute` configuration options instead.
42
+ * Joel Low - The table definition migration helper should follow the gem configuration
43
+ when generating column names.
44
+ * Joel Low - When deciding whether to generate a `deleter_id` column, check the gem
45
+ configuration for the `deleter_attribute` configuration option instead of
46
+ relying on the user to specify in every migration.
47
+ * Joel Low - Remove the `deleter` option from the `stampable` model declaration.
48
+ * Joel Low - Remove the `creator_attribute`, `updater_attribute`, and `deleter_attribute`
49
+ options from the `stampable` model declaration. All models will follow
50
+ the gem configuration.
51
+ * Joel Low - Added the `default_stamper` configuration option. The controller will
52
+ automatically stamp using that model.
53
+ * Joel Low - Additional attributes passed to `stampable` would be passed to the
54
+ underlying `belongs_to` association.
55
+ * Joel Low - Declare the creator/updater/deleter setter callbacks directly in
56
+ `ActiveRecord::Base`. So now, all models will automatically be stamped
57
+ when the creator/updater/deleter attributes are present. This mirrors
58
+ `ActiveRecord::Timestamp` behaviour.
59
+ * Joel Low - Automatically declare the creator/updater/deleter associations on every
60
+ model. To add additional configuration options, simply call `stampable`.
61
+ This can be called multiple times per model; the last call takes effect.
62
+ * Joel Low - Remove support for `serialized_attributes`. It will be removed in Rails 5.
63
+
64
+ ## 2.1.1 (9-7-2015)
65
+
66
+ * Chris Hilton - Only set updater attribute if the record has changed or contains a
67
+ serialized attribute.
68
+ * Chris Hilton - Support `:with_deleted` in the `stampable` declaration.
69
+ * Chris Hilton - Only set the creator attribute if it is blank.
70
+ * Chris Branson - Fix deprecation warning in `serialized_attributes`.
71
+ * Joel Low - Trigger the updater/creator stamping before saving, so that the correct
72
+ users are stamped even if validation was not run.
73
+ * Joel Low - Allow extra parameters to be passed to the migration helpers.
74
+
75
+ ## 2.1.0 (28-3-2014)
76
+ * Thomas von Deyen - Do not automatically make every class stampable.
77
+
78
+ ## 2.0.2 (11-8-2011)
79
+ * Chris Hilton - Set the creator/updater attributes before validation, so that they can
80
+ be checked as part of validations.
81
+ * Alex - Specify that the stampable class is camelized from the given symbol,
82
+ not just capitalized, to follow ActiveRecord convention.
83
+ ## 2.0.1 (8-10-2010)
84
+ * Michael Grosser - Make stampable define the deleter association and before filter whenever
85
+ a :deleter_attribute has been passed in options, or :deleter => true is
86
+ passed, or Caboose::Acts::Paranoid is defined. This makes :deleter
87
+ functionality useable to people who aren't use acts_as_paranoid.
88
+ * Michael Grosser - do not leave record_userstamp turned on when an exception occurs inside
89
+ the `without_stamps` block
90
+
91
+ ## 2.0 (2-17-2008)
92
+ * Ben Wyrosdick - Added a migration helper that gives migration scripts a <tt>userstamps</tt>
93
+ method.
94
+ * Marshall Roch - Stamping can be temporarily turned off using the 'without_stamps' class
95
+ method.
96
+ Example:
97
+ Post.without_stamps do
98
+ post = Post.find(params[:id])
99
+ post.update_attributes(params[:post])
100
+ post.save
101
+ end
102
+
103
+ * Models that should receive updates made by 'stampers' now use the acts_as_stampable class
104
+ method. This sets up the belongs_to relationships and also injects private methods for use by
105
+ the individual callback filter methods.
106
+
107
+ * Models that are responsible for updating now use the acts_as_stamper class method. This
108
+ injects the stamper= and stamper methods that are thread safe and should be updated per
109
+ request by a controller.
110
+
111
+ * The Userstamp module is now meant to be included with one of your project's controllers (the
112
+ Application Controller is recommended). It creates a before filter called 'set_stampers' that
113
+ is responsible for setting all the current Stampers.
114
+
115
+ ## 1.0 (01-18-2006)
116
+ * Initial Release
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,222 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ userstamp (4.0.0)
5
+ rails (>= 6)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actioncable (6.1.3.1)
11
+ actionpack (= 6.1.3.1)
12
+ activesupport (= 6.1.3.1)
13
+ nio4r (~> 2.0)
14
+ websocket-driver (>= 0.6.1)
15
+ actionmailbox (6.1.3.1)
16
+ actionpack (= 6.1.3.1)
17
+ activejob (= 6.1.3.1)
18
+ activerecord (= 6.1.3.1)
19
+ activestorage (= 6.1.3.1)
20
+ activesupport (= 6.1.3.1)
21
+ mail (>= 2.7.1)
22
+ actionmailer (6.1.3.1)
23
+ actionpack (= 6.1.3.1)
24
+ actionview (= 6.1.3.1)
25
+ activejob (= 6.1.3.1)
26
+ activesupport (= 6.1.3.1)
27
+ mail (~> 2.5, >= 2.5.4)
28
+ rails-dom-testing (~> 2.0)
29
+ actionpack (6.1.3.1)
30
+ actionview (= 6.1.3.1)
31
+ activesupport (= 6.1.3.1)
32
+ rack (~> 2.0, >= 2.0.9)
33
+ rack-test (>= 0.6.3)
34
+ rails-dom-testing (~> 2.0)
35
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
36
+ actiontext (6.1.3.1)
37
+ actionpack (= 6.1.3.1)
38
+ activerecord (= 6.1.3.1)
39
+ activestorage (= 6.1.3.1)
40
+ activesupport (= 6.1.3.1)
41
+ nokogiri (>= 1.8.5)
42
+ actionview (6.1.3.1)
43
+ activesupport (= 6.1.3.1)
44
+ builder (~> 3.1)
45
+ erubi (~> 1.4)
46
+ rails-dom-testing (~> 2.0)
47
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
48
+ activejob (6.1.3.1)
49
+ activesupport (= 6.1.3.1)
50
+ globalid (>= 0.3.6)
51
+ activemodel (6.1.3.1)
52
+ activesupport (= 6.1.3.1)
53
+ activerecord (6.1.3.1)
54
+ activemodel (= 6.1.3.1)
55
+ activesupport (= 6.1.3.1)
56
+ activestorage (6.1.3.1)
57
+ actionpack (= 6.1.3.1)
58
+ activejob (= 6.1.3.1)
59
+ activerecord (= 6.1.3.1)
60
+ activesupport (= 6.1.3.1)
61
+ marcel (~> 1.0.0)
62
+ mini_mime (~> 1.0.2)
63
+ activesupport (6.1.3.1)
64
+ concurrent-ruby (~> 1.0, >= 1.0.2)
65
+ i18n (>= 1.6, < 2)
66
+ minitest (>= 5.1)
67
+ tzinfo (~> 2.0)
68
+ zeitwerk (~> 2.3)
69
+ builder (3.2.4)
70
+ codeclimate-test-reporter (1.0.7)
71
+ simplecov
72
+ coderay (1.1.3)
73
+ concurrent-ruby (1.1.8)
74
+ coveralls (0.7.1)
75
+ multi_json (~> 1.3)
76
+ rest-client
77
+ simplecov (>= 0.7)
78
+ term-ansicolor
79
+ thor
80
+ crass (1.0.6)
81
+ diff-lcs (1.4.4)
82
+ docile (1.3.5)
83
+ domain_name (0.5.20190701)
84
+ unf (>= 0.0.5, < 1.0.0)
85
+ erubi (1.10.0)
86
+ globalid (0.4.2)
87
+ activesupport (>= 4.2.0)
88
+ http-accept (1.7.0)
89
+ http-cookie (1.0.3)
90
+ domain_name (~> 0.5)
91
+ i18n (1.8.10)
92
+ concurrent-ruby (~> 1.0)
93
+ loofah (2.9.1)
94
+ crass (~> 1.0.2)
95
+ nokogiri (>= 1.5.9)
96
+ mail (2.7.1)
97
+ mini_mime (>= 0.1.1)
98
+ marcel (1.0.1)
99
+ method_source (1.0.0)
100
+ mime-types (3.3.1)
101
+ mime-types-data (~> 3.2015)
102
+ mime-types-data (3.2021.0225)
103
+ mini_mime (1.0.3)
104
+ mini_portile2 (2.5.0)
105
+ minitest (5.14.4)
106
+ multi_json (1.15.0)
107
+ netrc (0.11.0)
108
+ nio4r (2.5.7)
109
+ nokogiri (1.11.3)
110
+ mini_portile2 (~> 2.5.0)
111
+ racc (~> 1.4)
112
+ pry (0.14.0)
113
+ coderay (~> 1.1)
114
+ method_source (~> 1.0)
115
+ racc (1.5.2)
116
+ rack (2.2.3)
117
+ rack-test (1.1.0)
118
+ rack (>= 1.0, < 3)
119
+ rails (6.1.3.1)
120
+ actioncable (= 6.1.3.1)
121
+ actionmailbox (= 6.1.3.1)
122
+ actionmailer (= 6.1.3.1)
123
+ actionpack (= 6.1.3.1)
124
+ actiontext (= 6.1.3.1)
125
+ actionview (= 6.1.3.1)
126
+ activejob (= 6.1.3.1)
127
+ activemodel (= 6.1.3.1)
128
+ activerecord (= 6.1.3.1)
129
+ activestorage (= 6.1.3.1)
130
+ activesupport (= 6.1.3.1)
131
+ bundler (>= 1.15.0)
132
+ railties (= 6.1.3.1)
133
+ sprockets-rails (>= 2.0.0)
134
+ rails-dom-testing (2.0.3)
135
+ activesupport (>= 4.2.0)
136
+ nokogiri (>= 1.6)
137
+ rails-html-sanitizer (1.3.0)
138
+ loofah (~> 2.3)
139
+ railties (6.1.3.1)
140
+ actionpack (= 6.1.3.1)
141
+ activesupport (= 6.1.3.1)
142
+ method_source
143
+ rake (>= 0.8.7)
144
+ thor (~> 1.0)
145
+ rake (13.0.3)
146
+ rdoc (6.3.0)
147
+ rest-client (2.1.0)
148
+ http-accept (>= 1.7.0, < 2.0)
149
+ http-cookie (>= 1.0.2, < 2.0)
150
+ mime-types (>= 1.16, < 4.0)
151
+ netrc (~> 0.8)
152
+ rspec (3.10.0)
153
+ rspec-core (~> 3.10.0)
154
+ rspec-expectations (~> 3.10.0)
155
+ rspec-mocks (~> 3.10.0)
156
+ rspec-core (3.10.1)
157
+ rspec-support (~> 3.10.0)
158
+ rspec-expectations (3.10.1)
159
+ diff-lcs (>= 1.2.0, < 2.0)
160
+ rspec-support (~> 3.10.0)
161
+ rspec-instafail (1.0.0)
162
+ rspec
163
+ rspec-mocks (3.10.2)
164
+ diff-lcs (>= 1.2.0, < 2.0)
165
+ rspec-support (~> 3.10.0)
166
+ rspec-rails (5.0.1)
167
+ actionpack (>= 5.2)
168
+ activesupport (>= 5.2)
169
+ railties (>= 5.2)
170
+ rspec-core (~> 3.10)
171
+ rspec-expectations (~> 3.10)
172
+ rspec-mocks (~> 3.10)
173
+ rspec-support (~> 3.10)
174
+ rspec-support (3.10.2)
175
+ simplecov (0.21.2)
176
+ docile (~> 1.1)
177
+ simplecov-html (~> 0.11)
178
+ simplecov_json_formatter (~> 0.1)
179
+ simplecov-html (0.12.3)
180
+ simplecov_json_formatter (0.1.2)
181
+ sprockets (4.0.2)
182
+ concurrent-ruby (~> 1.0)
183
+ rack (> 1, < 3)
184
+ sprockets-rails (3.2.2)
185
+ actionpack (>= 4.0)
186
+ activesupport (>= 4.0)
187
+ sprockets (>= 3.0.0)
188
+ sqlite3 (1.4.2)
189
+ sync (0.5.0)
190
+ term-ansicolor (1.7.1)
191
+ tins (~> 1.0)
192
+ thor (1.1.0)
193
+ tins (1.28.0)
194
+ sync
195
+ tzinfo (2.0.4)
196
+ concurrent-ruby (~> 1.0)
197
+ unf (0.1.4)
198
+ unf_ext
199
+ unf_ext (0.0.7.7)
200
+ websocket-driver (0.7.3)
201
+ websocket-extensions (>= 0.1.0)
202
+ websocket-extensions (0.1.5)
203
+ zeitwerk (2.4.2)
204
+
205
+ PLATFORMS
206
+ ruby
207
+
208
+ DEPENDENCIES
209
+ codeclimate-test-reporter
210
+ coveralls
211
+ pry
212
+ rake
213
+ rdoc
214
+ rspec
215
+ rspec-instafail
216
+ rspec-rails (>= 3.3)
217
+ simplecov
218
+ sqlite3
219
+ userstamp!
220
+
221
+ BUNDLED WITH
222
+ 2.1.4
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2006-2008 DeLynn Berry
2
+ Copyright (c) 2014-2015 Joel Low
3
+ Copyright (c) 2021 Priit Tark
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.
data/README.md ADDED
@@ -0,0 +1,142 @@
1
+ # Userstamper
2
+
3
+ ## Overview
4
+
5
+ Userstamp extends `ActiveRecord::Base` to add automatic updating of `creator` and `updater` attributes.
6
+
7
+ Two class methods (`model_stamper` and `stampable`) are implemented in this gem. The `model_stamper`
8
+ method is used in models that are responsible for creating or updating other objects.
9
+ Typically this would be the `User` model of your application. The `stampable` method is used in
10
+ models that are subject to being created or updated by stampers.
11
+
12
+ Gem is tested with Ruby 2.7.2 and Rails 6.1.3.1
13
+
14
+ ## Features
15
+ to result in a `belongs_to` relation which looks like:
16
+
17
+ ```ruby
18
+ belongs_to :creator, class_name: '::User', foreign_key: :created_by
19
+ ```
20
+
21
+ ### Saving before validation
22
+ This includes changes to perform model stamping before validation. This allows models to
23
+ enforce the presence of stamp attributes:
24
+
25
+ ```ruby
26
+ validates :created_by, presence: true
27
+ validates :updated_by, presence: true
28
+ ```
29
+
30
+ Furthermore, the `creator` attribute is set only if the value is blank allowing for a manual
31
+ override.
32
+
33
+ ## Usage
34
+ Assume that we are building a blog application, with User and Post objects. Add the following
35
+ to the application's Gemfile:
36
+
37
+ ```ruby
38
+ gem 'userstamper'
39
+ ```
40
+
41
+ Define an initializer in your Rails application to configure the gem:
42
+ config/initilialize/userstamper.rb:
43
+
44
+ ```ruby
45
+ Userstamper.configure do |config|
46
+ # config.default_stamper = 'User'
47
+ # config.creator_attribute = :creator_id
48
+ # config.updater_attribute = :updater_id
49
+ config.deleter_attribute = nil
50
+ end
51
+ ```
52
+
53
+ Ensure that each model has a set of columns for creators and updaters.
54
+
55
+ ```ruby
56
+ class CreateUsers < ActiveRecord::Migration
57
+ def change
58
+ create_table :users do |t|
59
+ ...
60
+ t.userstamps
61
+ end
62
+ end
63
+ end
64
+
65
+ class CreatePosts < ActiveRecord::Migration
66
+ def change
67
+ create_table :posts do |t|
68
+ ...
69
+ t.userstamps
70
+ end
71
+ end
72
+ end
73
+ ```
74
+
75
+ If you use `protect_from_forgery`, make sure the hooks are prepended:
76
+
77
+ ```ruby
78
+ class ApplicationController < ActionController::Base
79
+ protect_from_forgery with: :exception, prepend: true # with: anything will do, note `prepend: true`!
80
+ end
81
+ ```
82
+
83
+ Declare the stamper on the User model:
84
+
85
+ ```ruby
86
+ class User < ActiveRecord::Base
87
+ model_stamper
88
+ end
89
+ ```
90
+
91
+ If your stamper is called `User`, that's it; you're done.
92
+
93
+ ## Customisation
94
+ The association which is created on each of the `creator_id` and `updater_id` can
95
+ be customised. Also, the stamper used by each class can also be customised. For this purpose, the
96
+ `ActiveRecord::Base.stampable` method can be used:
97
+
98
+ ```ruby
99
+ class Post < ActiveRecord::Base
100
+ stampable
101
+ end
102
+ ```
103
+
104
+ The `stampable` method allows you to customize the `creator` and `updater` associations.
105
+ It also allows you to specify the name of the stamper for the class being declared. Any additional
106
+ arguments are passed to the `belongs_to` declaration.
107
+
108
+ ## Upgrade
109
+ When upgradeing from activerecord_userstamp gem, please remove deleted attributes.
110
+ Soft delete is not supported and not recommended. Soft delete is more pain in real life.
111
+
112
+ ## Tests
113
+ Run
114
+
115
+ $ bundle exec rspec
116
+
117
+ ## Forkception
118
+
119
+ This is a fork of:
120
+ - the [activerecord-userstamp](https://github.com/lowjoel/activerecord-userstamp) gem
121
+ - the [magiclabs-userstamp](https://github.com/magiclabs/userstamp) gem
122
+ - which is a fork of [Michael Grosser's](https://github.com/grosser)
123
+ [userstamp gem] (https://github.com/grosser/userstamp)
124
+ - which is a fork of the original [userstamp plugin](https://github.com/delynn/userstamp) by
125
+ [delynn](https://github.com/delynn)
126
+
127
+ In addition to these, some ideas are cherry picked from the following forks:
128
+
129
+ - [simplificator](https://github.com/simplificator/userstamp)
130
+ - [akm](https://github.com/akm/magic_userstamp)
131
+ - [konvenit](https://github.com/konvenit/userstamp)
132
+
133
+ ## Authors
134
+ - [DeLynn Berry](http://delynnberry.com/): The original idea for this plugin came from the Rails
135
+ Wiki article entitled
136
+ [Extending ActiveRecord](http://wiki.rubyonrails.com/rails/pages/ExtendingActiveRecordExample)
137
+ - [Michael Grosser](http://pragmatig.com)
138
+ - [John Dell](http://blog.spovich.com/)
139
+ - [Chris Hilton](https://github.com/chrismhilton)
140
+ - [Thomas von Deyen](https://github.com/tvdeyen)
141
+ - [Joel Low](http://joelsplace.sg)
142
+ - [Priit Tark](https://github.com/priit)