archival_record 3.0.1 → 4.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.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.envrc +9 -0
  3. data/.gitignore +1 -1
  4. data/.rubocop.yml +2 -3
  5. data/Appraisals +14 -0
  6. data/CHANGELOG.md +15 -2
  7. data/Gemfile.lock +68 -48
  8. data/LICENSE +1 -1
  9. data/README.md +61 -29
  10. data/archival_record.gemspec +15 -4
  11. data/gemfiles/rails_6.0.gemfile +2 -0
  12. data/gemfiles/rails_6.1.gemfile +2 -0
  13. data/gemfiles/rails_7.0.gemfile +2 -0
  14. data/gemfiles/rails_7.2.gemfile +7 -0
  15. data/gemfiles/rails_8.0.gemfile +7 -0
  16. data/lib/archival_record/version.rb +1 -1
  17. data/lib/archival_record.rb +2 -9
  18. data/lib/archival_record_core/archival_record.rb +19 -5
  19. data/lib/archival_record_core/archival_record_active_record_methods.rb +1 -3
  20. data/lib/archival_record_core/association_operation/archive.rb +0 -4
  21. data/lib/archival_record_core/association_operation/base.rb +25 -2
  22. data/shell.nix +41 -0
  23. data/test/associations_test.rb +22 -2
  24. data/test/bogus_relation_test.rb +2 -2
  25. data/test/callbacks_test.rb +14 -33
  26. data/test/exception_test.rb +9 -0
  27. data/test/fixtures/another_polys_holder.rb +1 -1
  28. data/test/fixtures/archival.rb +13 -7
  29. data/test/fixtures/archival_grandkid.rb +1 -1
  30. data/test/fixtures/archival_kid.rb +1 -1
  31. data/test/fixtures/archival_table_name.rb +1 -1
  32. data/test/fixtures/callback_archival.rb +13 -16
  33. data/test/fixtures/deprecated_warning_archival.rb +1 -1
  34. data/test/fixtures/exception_raiser.rb +11 -0
  35. data/test/fixtures/explicit_act_on_dependents_archival.rb +1 -1
  36. data/test/fixtures/exploder.rb +1 -1
  37. data/test/fixtures/ignorable_dependent.rb +1 -1
  38. data/test/fixtures/ignore_dependents_archival.rb +1 -1
  39. data/test/fixtures/independent_archival.rb +1 -1
  40. data/test/fixtures/many_many_archival.rb +9 -0
  41. data/test/fixtures/missing_archive_number.rb +1 -1
  42. data/test/fixtures/missing_archived_at.rb +1 -1
  43. data/test/fixtures/nonignorable_dependent.rb +1 -1
  44. data/test/fixtures/plain.rb +1 -1
  45. data/test/fixtures/poly.rb +1 -1
  46. data/test/fixtures/readonly_when_archived.rb +1 -1
  47. data/test/performance/the_test.rb +29 -0
  48. data/test/schema.rb +14 -12
  49. data/test/scope_test.rb +2 -2
  50. data/test/test_helper.rb +19 -5
  51. metadata +48 -12
  52. data/.gitlab-ci.yml +0 -20
  53. data/.rubocop_todo.yml +0 -7
  54. data/test/application_record_test.rb +0 -20
  55. data/test/fixtures/application_record_row.rb +0 -8
  56. /data/test/{fixtures/application_record.rb → application_record.rb} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: de698cb4c6c28dbc975343cbb8c64040423a401fe1963486e4d43feacdaf70fd
4
- data.tar.gz: 423dc258212a7b8ff4fb78a6acc29bc979846820c50263859e0d9d2a9e634c81
3
+ metadata.gz: a75201e40595114329b5ecf7f2e790a37c57a94640755fc50fc2d330f2065056
4
+ data.tar.gz: 7fa088f8c71f94aa613807d0f493178db771b993c41f1a0b266665940137eea9
5
5
  SHA512:
6
- metadata.gz: a24054ef6cd9fc3ed12233e10e11fa194e26f72499534925bdd4d4bad05b9245bb994763ba6b449b7100e48dda00ce30de641b51f9d6a797697fba2805335f84
7
- data.tar.gz: 3dab3e39d40c31fcfe60129b8eb9a3fb420be3ece65c18a7bfa3da367026b9c44ecee1e4b721ea71bd28cc85920308d427d391ddab10e2a0a82e1e2203e9ff30
6
+ metadata.gz: e5b6fb27d71b390549bbbcb50de73c000432521083f662e1f77ffdea2904b6782df8f54cc54a088946a6aacd4cf104e5c9d531e9a5d88851aca954ab74f5062c
7
+ data.tar.gz: d0daae3db6a6841c4185c0be8d25e0459df61f21b3d41c0f898cb18b06bcc9ac4a9d6867ee0f73c4246b08850aca8bad095df3ef05f5b8bf54ec33e4e2d3b836
data/.envrc ADDED
@@ -0,0 +1,9 @@
1
+ PATH_add bin
2
+
3
+ use nix
4
+
5
+ mkdir -p .nix-bundler
6
+
7
+ export BUNDLE_PATH=./vendor/bundle
8
+ export PATH=$PWD/bin:$PATH
9
+ export AR_LOGGER=0
data/.gitignore CHANGED
@@ -3,7 +3,7 @@
3
3
  .bundle
4
4
  bin
5
5
  vendor/bundle
6
- .nix-bundler
6
+ gemfiles/vendor/bundle
7
7
  *.gem
8
8
  gemfiles/*.lock
9
9
  pkg/*
data/.rubocop.yml CHANGED
@@ -1,5 +1,4 @@
1
- inherit_from: .rubocop_todo.yml
2
- require:
1
+ plugins:
3
2
  - rubocop-rails
4
3
  - rubocop-rake
5
4
 
@@ -54,7 +53,7 @@ Style/AsciiComments:
54
53
 
55
54
  # TODO: class documentation
56
55
  Style/Documentation:
57
- Enabled: false
56
+ Enabled: true
58
57
 
59
58
  Style/DoubleNegation:
60
59
  Enabled: false
data/Appraisals CHANGED
@@ -1,15 +1,29 @@
1
1
  appraise "rails-6.0" do
2
2
  gem "rails", "~> 6.0.0"
3
+ gem "sqlite3", "< 2"
4
+ gem "logger"
3
5
  end
4
6
 
5
7
  appraise "rails-6.1" do
6
8
  gem "rails", "~> 6.1.0"
9
+ gem "sqlite3", "< 2"
10
+ gem "logger"
7
11
  end
8
12
 
9
13
  appraise "rails-7.0" do
10
14
  gem "rails", "~> 7.0.0"
15
+ gem "sqlite3", "< 2"
16
+ gem "logger"
11
17
  end
12
18
 
13
19
  appraise "rails-7.1" do
14
20
  gem "rails", "~> 7.1.0"
15
21
  end
22
+
23
+ appraise "rails-7.2" do
24
+ gem "rails", "~> 7.2.0"
25
+ end
26
+
27
+ appraise "rails-8.0" do
28
+ gem "rails", "~> 8.0.0"
29
+ end
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 4.0.1 - March 25, 2025
4
+ * Fixing links on rubygems.org to point to codeberg since that config move to [metadata](https://guides.rubygems.org/specification-reference/#metadata) in the past couple years
5
+
6
+ ## 4.0.0 - March 19, 2025
7
+ * **BREAKING CHANGE** `unarchive` behavior changed if you had non-`dependent: :destroy` `has_many` relationship but equal archive numbers on archived records before, the associated record would be unarchived. Now it won't. *You probably weren't doing this. If you were, why? How did you find out you could? Did you intend to? Anyway I broke it for you if you did find this extremely odd edge case. Sorry.* see: https://codeberg.org/joelmeador/archival_record/commit/19e02708f5ec97aa9b56a51cb7a84283e73e65aa
8
+ * **BREAKING CHANGE** `archive` and `unarchive` now will act on `has_many` relations that are marked as `dependent: :delete_all` and `dependent: :destroy_async` in addition to `dependent: :destroy`. see: https://codeberg.org/joelmeador/archival_record/commit/685d7c6abb123422f2f8665252b99423dada305a
9
+ * added explicit Rails 7.1, 7.2, 8.0 support
10
+ * move from gitlab -> codeberg, remove CI because who needs it
11
+ * update main dev gemfile to active record 8 and clean up sqlite situation
12
+ * simplify the built-in scopes for `archived`/`unarchived` to only check `archive_number`. see: https://codeberg.org/joelmeador/archival_record/commit/36febe5bfab0a3638b7fa21718ca87e2e3e82c09
13
+ * Added `raise_on_error` option to main `archival_record` method to optionally not swallow exceptions that previously were. see: https://codeberg.org/joelmeador/archival_record/commit/ca99dac35f33d9f89bd10cf9846d975ab34a467a
14
+
3
15
  ## 3.0.1 - June 10, 2024
4
16
  * a few more tidying items like fixing up some raw sql in a query to be arel
5
17
  * changing a logging method to use error instead of debug so it surfaces more easily
@@ -10,6 +22,7 @@
10
22
  * **ADDED** new option for `archival_record` called `archive_dependents` which can control whether `dependent: :destroy` records are archived with their parent
11
23
  * lots of cleanup of code, particularly the way `ApplicationRecord` gets patched
12
24
  * remove travis-ci, use gitlab pipelines
25
+ * updated all gems that could be updated to latest
13
26
 
14
27
  ## 2.0.2 - August 4, 2020
15
28
  * fixing travis
@@ -17,7 +30,7 @@
17
30
 
18
31
  ## 2.0.1 - August 3, 2020
19
32
  * Add security policy
20
- * Update depenedent gems: archival_record (:D oops) and rubocop, and dependencies
33
+ * Update depenedent gems: `archival_record` (:D oops) and `rubocop`, and their dependencies
21
34
 
22
35
  ## 2.0.0 – August 3, 2020
23
36
 
@@ -25,7 +38,7 @@
25
38
  * **BREAKING CHANGE** Removed deprecated methods
26
39
  * Fix Rails 6 deprecation warnings
27
40
  * Renamed gem to [ArchivalRecord](https://github.com/janxious/archival_record/)
28
- * `acts_as_archival` becomes `archival_record` in models with a deprecation warning.
41
+ * `acts_as_archival` becomes `archival_record` in models with a deprecation warning for `acts_as_archival`.
29
42
 
30
43
  -------
31
44
 
data/Gemfile.lock CHANGED
@@ -1,106 +1,126 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- archival_record (3.0.1)
4
+ archival_record (4.0.0)
5
5
  activerecord (>= 6.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activemodel (7.1.3.4)
11
- activesupport (= 7.1.3.4)
12
- activerecord (7.1.3.4)
13
- activemodel (= 7.1.3.4)
14
- activesupport (= 7.1.3.4)
10
+ activejob (8.0.2)
11
+ activesupport (= 8.0.2)
12
+ globalid (>= 0.3.6)
13
+ activemodel (8.0.2)
14
+ activesupport (= 8.0.2)
15
+ activerecord (8.0.2)
16
+ activemodel (= 8.0.2)
17
+ activesupport (= 8.0.2)
15
18
  timeout (>= 0.4.0)
16
- activesupport (7.1.3.4)
19
+ activesupport (8.0.2)
17
20
  base64
21
+ benchmark (>= 0.3)
18
22
  bigdecimal
19
- concurrent-ruby (~> 1.0, >= 1.0.2)
23
+ concurrent-ruby (~> 1.0, >= 1.3.1)
20
24
  connection_pool (>= 2.2.5)
21
25
  drb
22
26
  i18n (>= 1.6, < 2)
27
+ logger (>= 1.4.2)
23
28
  minitest (>= 5.1)
24
- mutex_m
25
- tzinfo (~> 2.0)
29
+ securerandom (>= 0.3)
30
+ tzinfo (~> 2.0, >= 2.0.5)
31
+ uri (>= 0.13.1)
26
32
  appraisal (2.5.0)
27
33
  bundler
28
34
  rake
29
35
  thor (>= 0.14.0)
30
- ast (2.4.2)
36
+ ast (2.4.3)
31
37
  base64 (0.2.0)
32
- bigdecimal (3.1.8)
33
- concurrent-ruby (1.3.3)
34
- connection_pool (2.4.1)
35
- database_cleaner (2.0.2)
38
+ benchmark (0.4.0)
39
+ bigdecimal (3.1.9)
40
+ coderay (1.1.3)
41
+ concurrent-ruby (1.3.5)
42
+ connection_pool (2.5.0)
43
+ database_cleaner (2.1.0)
36
44
  database_cleaner-active_record (>= 2, < 3)
37
- database_cleaner-active_record (2.1.0)
45
+ database_cleaner-active_record (2.2.0)
38
46
  activerecord (>= 5.a)
39
47
  database_cleaner-core (~> 2.0.0)
40
48
  database_cleaner-core (2.0.1)
41
49
  drb (2.2.1)
42
- i18n (1.14.5)
50
+ globalid (1.2.1)
51
+ activesupport (>= 6.1)
52
+ i18n (1.14.7)
43
53
  concurrent-ruby (~> 1.0)
44
- json (2.7.2)
45
- language_server-protocol (3.17.0.3)
46
- mini_portile2 (2.8.7)
47
- minitest (5.23.1)
48
- mutex_m (0.2.0)
49
- parallel (1.25.1)
50
- parser (3.3.2.0)
54
+ json (2.10.2)
55
+ language_server-protocol (3.17.0.4)
56
+ lint_roller (1.1.0)
57
+ logger (1.6.6)
58
+ method_source (1.1.0)
59
+ mini_portile2 (2.8.8)
60
+ minitest (5.25.5)
61
+ parallel (1.26.3)
62
+ parser (3.3.7.1)
51
63
  ast (~> 2.4.1)
52
64
  racc
53
- racc (1.8.0)
54
- rack (3.0.11)
65
+ pry (0.15.2)
66
+ coderay (~> 1.1)
67
+ method_source (~> 1.0)
68
+ racc (1.8.1)
69
+ rack (3.1.12)
55
70
  rainbow (3.1.1)
56
71
  rake (13.2.1)
57
- regexp_parser (2.9.2)
58
- rexml (3.2.9)
59
- strscan
60
- rr (3.1.0)
61
- rubocop (1.64.1)
72
+ regexp_parser (2.10.0)
73
+ rr (3.1.1)
74
+ rubocop (1.74.0)
62
75
  json (~> 2.3)
63
- language_server-protocol (>= 3.17.0)
76
+ language_server-protocol (~> 3.17.0.2)
77
+ lint_roller (~> 1.1.0)
64
78
  parallel (~> 1.10)
65
79
  parser (>= 3.3.0.2)
66
80
  rainbow (>= 2.2.2, < 4.0)
67
- regexp_parser (>= 1.8, < 3.0)
68
- rexml (>= 3.2.5, < 4.0)
69
- rubocop-ast (>= 1.31.1, < 2.0)
81
+ regexp_parser (>= 2.9.3, < 3.0)
82
+ rubocop-ast (>= 1.38.0, < 2.0)
70
83
  ruby-progressbar (~> 1.7)
71
- unicode-display_width (>= 2.4.0, < 3.0)
72
- rubocop-ast (1.31.3)
84
+ unicode-display_width (>= 2.4.0, < 4.0)
85
+ rubocop-ast (1.40.0)
73
86
  parser (>= 3.3.1.0)
74
- rubocop-rails (2.25.0)
87
+ rubocop-rails (2.30.3)
75
88
  activesupport (>= 4.2.0)
89
+ lint_roller (~> 1.1)
76
90
  rack (>= 1.1)
77
- rubocop (>= 1.33.0, < 2.0)
78
- rubocop-ast (>= 1.31.1, < 2.0)
79
- rubocop-rake (0.6.0)
80
- rubocop (~> 1.0)
91
+ rubocop (>= 1.72.1, < 2.0)
92
+ rubocop-ast (>= 1.38.0, < 2.0)
93
+ rubocop-rake (0.7.1)
94
+ lint_roller (~> 1.1)
95
+ rubocop (>= 1.72.1)
81
96
  ruby-progressbar (1.13.0)
82
- sqlite3 (1.7.3)
97
+ securerandom (0.4.1)
98
+ sqlite3 (2.6.0)
83
99
  mini_portile2 (~> 2.8.0)
84
- strscan (3.1.0)
85
- thor (1.3.1)
86
- timeout (0.4.1)
100
+ thor (1.3.2)
101
+ timeout (0.4.3)
87
102
  tzinfo (2.0.6)
88
103
  concurrent-ruby (~> 1.0)
89
- unicode-display_width (2.5.0)
104
+ unicode-display_width (3.1.4)
105
+ unicode-emoji (~> 4.0, >= 4.0.4)
106
+ unicode-emoji (4.0.4)
107
+ uri (1.0.3)
90
108
 
91
109
  PLATFORMS
92
110
  ruby
93
111
 
94
112
  DEPENDENCIES
113
+ activejob (>= 6.0)
95
114
  appraisal
96
115
  archival_record!
97
116
  database_cleaner
117
+ pry
98
118
  rake
99
119
  rr
100
120
  rubocop
101
121
  rubocop-rails
102
122
  rubocop-rake
103
- sqlite3 (< 2)
123
+ sqlite3
104
124
 
105
125
  BUNDLED WITH
106
126
  2.5.11
data/LICENSE CHANGED
@@ -5,7 +5,7 @@ All other copyright for project ArchivalRecord are held by Joel Meador, 2020.
5
5
 
6
6
  -----
7
7
 
8
- LICENSE for [ArchivalRecord](https://gitlab.com/joelmeador/archival_record/)
8
+ LICENSE for [ArchivalRecord](https://codeberg.org/joelmeador/archival_record/)
9
9
 
10
10
  Copyright (c) 2020 Joel Meador
11
11
 
data/README.md CHANGED
@@ -10,9 +10,9 @@ Additionally, other plugins generally change how `destroy`/`delete` work. Archiv
10
10
 
11
11
  _This is a fork of [ActsAsArchival](https://github.com/expectedbehavior/acts_as_archival/)._
12
12
 
13
- ## Maintenance
13
+ ## Maintenance Schedule
14
14
 
15
- You might read the commit logs and think "This must be abandonware! This hasn't been updated in 2y!" But! This is a mature project that solves a specific problem in ActiveRecord. It tends to only be updated when a new major version of ActiveRecord comes out and hence the infrequent updates.
15
+ You might read the commit logs and think "This must be abandonware! This hasn't been updated in X years!" But! This is a mature project that solves a specific problem in ActiveRecord. It tends to only be updated when a new major version of ActiveRecord comes out and hence the infrequent updates.
16
16
 
17
17
  ## Install
18
18
 
@@ -24,7 +24,7 @@ Any models you want to be archival should have the columns `archive_number` (`St
24
24
 
25
25
  i.e. `rails g migration AddArchivalRecordToPost archive_number archived_at:datetime`
26
26
 
27
- Any dependent-destroy ArchivalRecord model associated to an ArchivalRecord model will be archived with its parent.
27
+ Any `dependent: :destroy`, `dependent: :delete_all`, or `dependent: :destroy_async` ArchivalRecord model associated to an ArchivalRecord model will be archived with its parent.
28
28
 
29
29
  _If you're stuck on Rails 5x/4x/3x/2x, check out the older tags/branches, which are no longer in active development._
30
30
 
@@ -60,15 +60,17 @@ h.archived_at # => nil
60
60
 
61
61
  ``` ruby
62
62
  h = Hole.create #
63
- r = h.rats.create #
63
+ rat = h.rats.create #
64
64
  h.archive! # => true
65
65
  h.archive_number # => "b56876de48a5dcfe71b2c13eec15e4a2"
66
- r.archived_at # => Thu, 01 Jan 2012 01:52:12 -0400
67
- r.archived? # => true
66
+ rat.archive_number # => "b56876de48a5dcfe71b2c13eec15e4a2"
67
+ rat.archived_at # => Thu, 01 Jan 2012 01:52:12 -0400
68
+ rat.archived? # => true
68
69
  h.unarchive! # => true
69
70
  h.archive_number # => nil
70
- r.archived_at # => nil
71
- r.archived? # => false
71
+ rat.archive_number # => nil
72
+ rat.archived_at # => nil
73
+ rat.archived? # => false
72
74
  ```
73
75
 
74
76
  ### Relations
@@ -122,14 +124,17 @@ class CantTouchThis < ApplicationRecord
122
124
  end
123
125
 
124
126
  record = CantTouchThis.create(foo: "bar")
125
- record.archive! # => true
127
+ record.archive! # => true
126
128
  record.foo = "I want this to work"
127
- record.save # => false
128
- record.errors.full_messages.first # => "Cannot modify an archived record."
129
+ record.save # => false
130
+ record.errors.full_messages.first # => "Cannot modify an archived record."
129
131
  ```
130
132
 
131
133
  #### `archive_dependents`
132
- When defining an ArchivalRecord model, it is possible to deactivate archiving/unarchiving for `dependent: :destroy` relationships that are tied to ArchivalRecord models by passing `archive_dependents: false` to the `archival_record` call in your model. The default value of this option is `true`.
134
+ When defining an ArchivalRecord model, it is possible to deactivate archiving/unarchiving for
135
+ `dependent: :destroy` relationships that are tied to ArchivalRecord models by passing
136
+ `archive_dependents: false` to the `archival_record` call in your model. The default value of
137
+ this option is `true`.
133
138
 
134
139
  ``` ruby
135
140
  class WillArchive < ApplicationRecord
@@ -148,6 +153,27 @@ record.archived? # => true
148
153
  wont_archive.archived? # => false
149
154
  ```
150
155
 
156
+ #### `raise_on_error`
157
+
158
+ The default behavior of ArchivalRecord models when archiving or unarchiving and a `StandardError`
159
+ is encountered during the transaction is to quietly roll back the transaction. If you would like
160
+ an exception to occur instead - this is useful for debugging and maybe appropriate for production
161
+ depending on your circumstances - you can set pass `raise_on_error: true` to the `archival_record`
162
+ call in your model. The default value of this option is `false`.
163
+
164
+
165
+ ``` ruby
166
+ class ExplodesWhenTouched < ApplicationRecord
167
+ archival_record raise_on_error: true
168
+ end
169
+
170
+ record = ExplodesWhenTouched.create(foo: "bar")
171
+ record.archive! # => true
172
+ record.readonly!
173
+ record.unarchive! # => raises ActiveRecord::ReadOnlyRecord
174
+ ```
175
+
176
+
151
177
  ### Callbacks
152
178
 
153
179
  ArchivalRecord models have four additional callbacks to do any necessary cleanup or other processing before and after archiving and unarchiving, and can additionally halt the archive callback chain.
@@ -174,14 +200,12 @@ end
174
200
 
175
201
  #### Halting the callback chain
176
202
 
177
- * Rails 4.2 - the callback method should return a `false`/`nil` value.
178
- * Rails 5.x - the callback should `throw(:abort)`/`raise(:abort)`.
203
+ * Rails 6.x+ - the callback should `throw(:abort)`/`raise(:abort)`.
179
204
 
180
205
  ## Caveats
181
206
 
182
- 1. This will only work on associations that are dependent destroy. It
183
- should be trivial to change that or make it optional.
184
- 1. If you would like to work on this, you will need to setup sqlite on your development machine. Alternately, you can deactivate specific dev dependencies in the gemspec and test_helper and ask for help.
207
+ 1. This will only work on associations that are marked `dependent: :destroy`, `dependent: :delete_all`, or `dependent: :destroy_async`. It should be straightforward to change that or make it optional.
208
+ 1. If you would like to work on this, you will need to setup sqlite on your development machine. Alternately, you can deactivate specific dev dependencies in the `gemspec` and `test_helper` or ask for help in an issue.
185
209
 
186
210
  ## Compatibility with ActsAsArchival
187
211
 
@@ -197,11 +221,17 @@ rake # run tests on latest Rails
197
221
  appraisal rake # run tests on all versions of Rails
198
222
  ```
199
223
 
224
+ If you need test logs, run with the env variable `AR_LOGGER` set to `1` i.e.
225
+
226
+ ``` bash
227
+ AR_LOGGER=1 rake
228
+ ```
229
+
200
230
  Check out [more on appraisal](https://github.com/thoughtbot/appraisal#usage) if you need to add new versions of things or run into a version bug.
201
231
 
202
232
  ## Help Wanted
203
233
 
204
- We'd love to have your help making this better! If you have ideas for features this should implement or you think the code sucks, let us know. And PRs are greatly appreciated. :+1:
234
+ I'd love to have your help making this better! If you have ideas for features this should implement or you think the code sucks, let us know. And PRs are greatly appreciated. :+1:
205
235
 
206
236
  ## Thanks
207
237
 
@@ -210,23 +240,25 @@ ActsAsParanoid and PermanentRecords were both inspirations for this:
210
240
  * http://github.com/technoweenie/acts_as_paranoid
211
241
  * http://github.com/fastestforward/permanent_records
212
242
 
213
- ## Contributors
243
+ ## Contributors - Issues and Code!
214
244
 
215
245
  * Joel Meador
216
- * Michael Kuehl
217
- * Matthew Gordon
218
- * Vojtech Salbaba
219
- * David Jones
220
- * Dave Woodward
221
- * Miles Sterrett
222
- * James Hill
223
- * Maarten Claes
224
- * Anthony Panozzo
225
246
  * Aaron Milam
247
+ * Anthony Panozzo
226
248
  * Anton Rieder
249
+ * Dave Woodward
250
+ * David Jones
251
+ * Elijah Miller
252
+ * James Hill
227
253
  * Josh Menden
254
+ * Maarten Claes
255
+ * Matthew Gordon
256
+ * Michael Kuehl
257
+ * Miles Sterrett
228
258
  * Sergey Gnuskov
229
- * Elijah Miller
259
+ * Vojtech Salbaba
260
+ * Lee Bernick
261
+ * Chris Thornberry
230
262
 
231
263
  Thanks!
232
264
 
@@ -22,9 +22,7 @@ Gem::Specification.new do |gem|
22
22
  "Sergey Gnuskov",
23
23
  "Elijah Miller"]
24
24
  gem.email = ["joel.meador+archival_record@gmail.com"]
25
- gem.homepage = "https://gitlab.com/joelmeador/archival_record/"
26
25
  gem.licenses = ["MIT"]
27
-
28
26
  gem.files = `git ls-files`.split("\n")
29
27
  gem.require_paths = ["lib"]
30
28
  gem.required_ruby_version = ">= 3.0"
@@ -32,14 +30,16 @@ Gem::Specification.new do |gem|
32
30
  gem.add_dependency("activerecord", ">= 6.0")
33
31
 
34
32
  # rubocop:disable Gemspec/DevelopmentDependencies
33
+ gem.add_development_dependency("activejob", ">= 6.0")
35
34
  gem.add_development_dependency("appraisal")
36
35
  gem.add_development_dependency("database_cleaner")
36
+ gem.add_development_dependency("pry")
37
37
  gem.add_development_dependency("rake")
38
38
  gem.add_development_dependency("rr")
39
39
  gem.add_development_dependency("rubocop")
40
40
  gem.add_development_dependency("rubocop-rails")
41
41
  gem.add_development_dependency("rubocop-rake")
42
- gem.add_development_dependency("sqlite3", "< 2")
42
+ gem.add_development_dependency("sqlite3")
43
43
  # rubocop:enable Gemspec/DevelopmentDependencies
44
44
 
45
45
  gem.description =
@@ -52,5 +52,16 @@ Gem::Specification.new do |gem|
52
52
 
53
53
  Additionally, other plugins generally change how destroy/delete work. ArchivalRecord does not, and thus one can destroy records like normal.
54
54
  DESCRIPTION
55
- gem.metadata["rubygems_mfa_required"] = "true"
55
+
56
+ gem.metadata = {
57
+ "bug_tracker_uri" => "https://codeberg.org/joelmeador/archival_record/issues",
58
+ "changelog_uri" => "https://codeberg.org/joelmeador/archival_record/src/branch/main/CHANGELOG.md",
59
+ "homepage_uri" => "https://codeberg.org/joelmeador/archival_record/",
60
+ "rubygems_mfa_required" => "true",
61
+ "source_code_uri" => "https://codeberg.org/joelmeador/archival_record/",
62
+ # "documentation_uri" => "https://www.example.info/gems/bestgemever/0.0.1",
63
+ # "funding_uri" => "https://example.com/donate"
64
+ # "mailing_list_uri" => "https://groups.example.com/bestgemever",
65
+ # "wiki_uri" => "https://example.com/user/bestgemever/wiki",
66
+ }
56
67
  end
@@ -3,5 +3,7 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 6.0.0"
6
+ gem "sqlite3", "< 2"
7
+ gem "logger"
6
8
 
7
9
  gemspec path: "../"
@@ -3,5 +3,7 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 6.1.0"
6
+ gem "sqlite3", "< 2"
7
+ gem "logger"
6
8
 
7
9
  gemspec path: "../"
@@ -3,5 +3,7 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 7.0.0"
6
+ gem "sqlite3", "< 2"
7
+ gem "logger"
6
8
 
7
9
  gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 7.2.0"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 8.0.0"
6
+
7
+ gemspec path: "../"
@@ -1,5 +1,5 @@
1
1
  module ArchivalRecord
2
2
 
3
- VERSION = "3.0.1".freeze
3
+ VERSION = "4.0.1".freeze
4
4
 
5
5
  end
@@ -7,13 +7,6 @@ require "archival_record_core/association_operation/unarchive"
7
7
  require "archival_record_core/archival_record"
8
8
  require "archival_record_core/archival_record_active_record_methods"
9
9
 
10
- # This assumes a fully Rails 5 compatible set of ActiveRecord models
11
- if defined?(ApplicationRecord)
12
- ApplicationRecord.include ArchivalRecordCore::ArchivalRecord
13
- ApplicationRecord.include ArchivalRecordCore::ArchivalRecordActiveRecordMethods
14
- else
15
- ActiveSupport.on_load(:active_record) { include ArchivalRecordCore::ArchivalRecord }
16
- ActiveSupport.on_load(:active_record) { include ArchivalRecordCore::ArchivalRecordActiveRecordMethods }
17
- end
18
-
10
+ ApplicationRecord.include ArchivalRecordCore::ArchivalRecord
11
+ ApplicationRecord.include ArchivalRecordCore::ArchivalRecordActiveRecordMethods
19
12
  ActiveRecord::Relation.include ArchivalRecordCore::ArchivalRecordActiveRecordMethods::ARRelationMethods
@@ -1,4 +1,7 @@
1
+ # Namespace for containing core extensions to active record
1
2
  module ArchivalRecordCore
3
+ # Primary holding module for defining our custom errors and the method installer that
4
+ # gets added to ApplicationRecord
2
5
  module ArchivalRecord
3
6
 
4
7
  require "digest/md5"
@@ -18,6 +21,8 @@ module ArchivalRecordCore
18
21
  base.extend ActMethods
19
22
  end
20
23
 
24
+ # this defines the class-level methods used to setup the archival record work on a given
25
+ # class.
21
26
  module ActMethods
22
27
 
23
28
  def archival_record(options = {})
@@ -41,10 +46,15 @@ module ArchivalRecordCore
41
46
  end
42
47
 
43
48
  private def setup_options(options)
44
- default_options = { readonly_when_archived: false, archive_dependents: true }
49
+ default_options = {
50
+ readonly_when_archived: false,
51
+ archive_dependents: true,
52
+ raise_on_error: false
53
+ }
45
54
  options.reverse_merge!(default_options)
46
55
 
47
56
  define_method(:archive_dependents?) { options[:archive_dependents] }
57
+ define_method(:archival_raise_on_error?) { options[:raise_on_error] }
48
58
  end
49
59
 
50
60
  private def setup_validations(options)
@@ -53,8 +63,8 @@ module ArchivalRecordCore
53
63
  end
54
64
 
55
65
  private def setup_scopes
56
- scope :archived, -> { where.not(archived_at: nil).where.not(archive_number: nil) }
57
- scope :unarchived, -> { where(archived_at: nil, archive_number: nil) }
66
+ scope :archived, -> { where.not(archive_number: nil) }
67
+ scope :unarchived, -> { where(archive_number: nil) }
58
68
  scope :archived_from_archive_number,
59
69
  (lambda do |head_archive_number|
60
70
  table = arel_table
@@ -87,6 +97,7 @@ module ArchivalRecordCore
87
97
  private def define_callback_dsl_method(callbackable_type, action)
88
98
  # rubocop:disable Security/Eval
89
99
  eval <<-END_CALLBACKS, binding, __FILE__, __LINE__ + 1
100
+ # The below block gets turned into something like this:
90
101
  # unless defined?(before_archive)
91
102
  # def before_archive(*args, &blk)
92
103
  # set_callback(:archive, :before, *args, &blk)
@@ -170,8 +181,11 @@ module ArchivalRecordCore
170
181
  end
171
182
 
172
183
  private def handle_archival_action_exception(exception)
173
- ActiveRecord::Base.logger.try(:error, exception.message)
174
- ActiveRecord::Base.logger.try(:error, exception.backtrace)
184
+ ApplicationRecord.logger.try(:error, exception.message)
185
+ ApplicationRecord.logger.try(:error, exception.backtrace)
186
+
187
+ raise if archival_raise_on_error?
188
+
175
189
  raise(ActiveRecord::Rollback)
176
190
  end
177
191