archival_record 3.0.0 → 4.0.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 +4 -4
- data/.envrc +9 -0
- data/.gitignore +1 -1
- data/.rubocop.yml +1 -1
- data/Appraisals +14 -0
- data/CHANGELOG.md +16 -2
- data/Gemfile.lock +67 -47
- data/LICENSE +1 -1
- data/README.md +63 -31
- data/archival_record.gemspec +5 -3
- data/gemfiles/rails_6.0.gemfile +2 -0
- data/gemfiles/rails_6.1.gemfile +2 -0
- data/gemfiles/rails_7.0.gemfile +2 -0
- data/gemfiles/rails_7.2.gemfile +7 -0
- data/gemfiles/rails_8.0.gemfile +7 -0
- data/lib/archival_record/version.rb +1 -1
- data/lib/archival_record.rb +2 -9
- data/lib/archival_record_core/archival_record.rb +21 -8
- data/lib/archival_record_core/archival_record_active_record_methods.rb +1 -3
- data/lib/archival_record_core/association_operation/archive.rb +0 -4
- data/lib/archival_record_core/association_operation/base.rb +25 -2
- data/shell.nix +41 -0
- data/test/associations_test.rb +22 -2
- data/test/bogus_relation_test.rb +22 -0
- data/test/callbacks_test.rb +14 -33
- data/test/exception_test.rb +9 -0
- data/test/fixtures/another_polys_holder.rb +1 -1
- data/test/fixtures/archival.rb +13 -7
- data/test/fixtures/archival_grandkid.rb +1 -1
- data/test/fixtures/archival_kid.rb +1 -1
- data/test/fixtures/archival_table_name.rb +1 -1
- data/test/fixtures/bogus_relation.rb +6 -0
- data/test/fixtures/{callback_archival4.rb → callback_archival.rb} +3 -2
- data/test/fixtures/deprecated_warning_archival.rb +1 -1
- data/test/fixtures/exception_raiser.rb +11 -0
- data/test/fixtures/explicit_act_on_dependents_archival.rb +1 -1
- data/test/fixtures/exploder.rb +1 -1
- data/test/fixtures/ignorable_dependent.rb +1 -1
- data/test/fixtures/ignore_dependents_archival.rb +1 -1
- data/test/fixtures/independent_archival.rb +1 -1
- data/test/fixtures/many_many_archival.rb +9 -0
- data/test/fixtures/missing_archive_number.rb +1 -1
- data/test/fixtures/missing_archived_at.rb +1 -1
- data/test/fixtures/nonignorable_dependent.rb +1 -1
- data/test/fixtures/plain.rb +1 -1
- data/test/fixtures/poly.rb +1 -1
- data/test/fixtures/readonly_when_archived.rb +1 -1
- data/test/performance/the_test.rb +29 -0
- data/test/schema.rb +19 -12
- data/test/scope_test.rb +3 -9
- data/test/test_helper.rb +30 -29
- metadata +47 -13
- data/.gitlab-ci.yml +0 -20
- data/test/application_record_test.rb +0 -20
- data/test/fixtures/application_record_row.rb +0 -8
- data/test/fixtures/callback_archival5.rb +0 -23
- /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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c315fb06fde509b19bfc47160a1f2d4a6ecfe7366f3d1282a79617ec52cd43a7
|
4
|
+
data.tar.gz: bec372e44222e0ca89c599a2394de54e4ae6487235efb07487f6069bf9896ea1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca80d2342eb66c07303c24260f9d09d8b6f2f2b6dff8f5a5f43e21e3cdf0a7d1dc3a149db270a23fb8ca51383d67323e9ef60ff4f1877a38ddb7e8859329ef7c
|
7
|
+
data.tar.gz: f40ccfc73c58ec33159f1cb0a400145f1f23c928f86623317841e09cf3220fe3ac4127a09d6d915fd9d7d3c98b0c8b5279131c0918c476293bd4f16ff1a7c9b9
|
data/.envrc
ADDED
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
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,11 +1,25 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 4.0.0 - March 19, 2025
|
4
|
+
* **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
|
5
|
+
* **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
|
6
|
+
* added explicit Rails 7.1, 7.2, 8.0 support
|
7
|
+
* move from gitlab -> codeberg, remove CI because who needs it
|
8
|
+
* update main dev gemfile to active record 8 and clean up sqlite situation
|
9
|
+
* simplify the built-in scopes for `archived`/`unarchived` to only check `archive_number`. see: https://codeberg.org/joelmeador/archival_record/commit/36febe5bfab0a3638b7fa21718ca87e2e3e82c09
|
10
|
+
* 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
|
11
|
+
|
12
|
+
## 3.0.1 - June 10, 2024
|
13
|
+
* a few more tidying items like fixing up some raw sql in a query to be arel
|
14
|
+
* changing a logging method to use error instead of debug so it surfaces more easily
|
15
|
+
|
3
16
|
## 3.0.0 - June 10, 2024
|
4
17
|
* **BREAKING CHANGE** Drop support for rails 5 - see `rails__4.x-and-5.x` branch for relevant code
|
5
18
|
* **BREAKING CHANGE** Drop support for Ruby 2.x
|
6
19
|
* **ADDED** new option for `archival_record` called `archive_dependents` which can control whether `dependent: :destroy` records are archived with their parent
|
7
20
|
* lots of cleanup of code, particularly the way `ApplicationRecord` gets patched
|
8
21
|
* remove travis-ci, use gitlab pipelines
|
22
|
+
* updated all gems that could be updated to latest
|
9
23
|
|
10
24
|
## 2.0.2 - August 4, 2020
|
11
25
|
* fixing travis
|
@@ -13,7 +27,7 @@
|
|
13
27
|
|
14
28
|
## 2.0.1 - August 3, 2020
|
15
29
|
* Add security policy
|
16
|
-
* Update depenedent gems: archival_record (:D oops) and rubocop
|
30
|
+
* Update depenedent gems: `archival_record` (:D oops) and `rubocop`, and their dependencies
|
17
31
|
|
18
32
|
## 2.0.0 – August 3, 2020
|
19
33
|
|
@@ -21,7 +35,7 @@
|
|
21
35
|
* **BREAKING CHANGE** Removed deprecated methods
|
22
36
|
* Fix Rails 6 deprecation warnings
|
23
37
|
* Renamed gem to [ArchivalRecord](https://github.com/janxious/archival_record/)
|
24
|
-
* `acts_as_archival` becomes `archival_record` in models with a deprecation warning
|
38
|
+
* `acts_as_archival` becomes `archival_record` in models with a deprecation warning for `acts_as_archival`.
|
25
39
|
|
26
40
|
-------
|
27
41
|
|
data/Gemfile.lock
CHANGED
@@ -1,106 +1,126 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
archival_record (
|
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
|
-
|
11
|
-
activesupport (=
|
12
|
-
|
13
|
-
|
14
|
-
activesupport (=
|
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 (
|
19
|
+
activesupport (8.0.2)
|
17
20
|
base64
|
21
|
+
benchmark (>= 0.3)
|
18
22
|
bigdecimal
|
19
|
-
concurrent-ruby (~> 1.0, >= 1.
|
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
|
-
|
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
36
|
ast (2.4.2)
|
31
37
|
base64 (0.2.0)
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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.
|
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
|
-
|
50
|
+
globalid (1.2.1)
|
51
|
+
activesupport (>= 6.1)
|
52
|
+
i18n (1.14.7)
|
43
53
|
concurrent-ruby (~> 1.0)
|
44
|
-
json (2.
|
45
|
-
language_server-protocol (3.17.0.
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
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
|
-
|
54
|
-
|
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.
|
58
|
-
|
59
|
-
|
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 (
|
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 (>=
|
68
|
-
|
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, <
|
72
|
-
rubocop-ast (1.
|
84
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
85
|
+
rubocop-ast (1.39.0)
|
73
86
|
parser (>= 3.3.1.0)
|
74
|
-
rubocop-rails (2.
|
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.
|
78
|
-
rubocop-ast (>= 1.
|
79
|
-
rubocop-rake (0.
|
80
|
-
|
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
|
-
|
97
|
+
securerandom (0.4.1)
|
98
|
+
sqlite3 (2.6.0)
|
83
99
|
mini_portile2 (~> 2.8.0)
|
84
|
-
|
85
|
-
|
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 (
|
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
|
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://
|
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
|
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
|
|
@@ -20,13 +20,13 @@ Gemfile:
|
|
20
20
|
|
21
21
|
`gem "archival_record"`
|
22
22
|
|
23
|
-
Any models you want to be archival should have the columns `archive_number` (String) and `archived_at` (DateTime).
|
23
|
+
Any models you want to be archival should have the columns `archive_number` (`String`) and `archived_at` (`DateTime`).
|
24
24
|
|
25
25
|
i.e. `rails g migration AddArchivalRecordToPost archive_number archived_at:datetime`
|
26
26
|
|
27
|
-
Any dependent
|
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
|
-
_If you're stuck on Rails
|
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
|
|
31
31
|
## Example
|
32
32
|
|
@@ -60,15 +60,17 @@ h.archived_at # => nil
|
|
60
60
|
|
61
61
|
``` ruby
|
62
62
|
h = Hole.create #
|
63
|
-
|
63
|
+
rat = h.rats.create #
|
64
64
|
h.archive! # => true
|
65
65
|
h.archive_number # => "b56876de48a5dcfe71b2c13eec15e4a2"
|
66
|
-
|
67
|
-
|
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
|
-
|
71
|
-
|
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!
|
127
|
+
record.archive! # => true
|
126
128
|
record.foo = "I want this to work"
|
127
|
-
record.save
|
128
|
-
record.errors.full_messages.first
|
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
|
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
|
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
|
183
|
-
|
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
|
-
|
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
|
-
*
|
259
|
+
* Vojtech Salbaba
|
260
|
+
* Lee Bernick
|
261
|
+
* Chris Thornberry
|
230
262
|
|
231
263
|
Thanks!
|
232
264
|
|
data/archival_record.gemspec
CHANGED
@@ -22,8 +22,8 @@ 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://
|
26
|
-
gem.licenses = [
|
25
|
+
gem.homepage = "https://codeberg.org/joelmeador/archival_record/"
|
26
|
+
gem.licenses = ["MIT"]
|
27
27
|
|
28
28
|
gem.files = `git ls-files`.split("\n")
|
29
29
|
gem.require_paths = ["lib"]
|
@@ -32,14 +32,16 @@ Gem::Specification.new do |gem|
|
|
32
32
|
gem.add_dependency("activerecord", ">= 6.0")
|
33
33
|
|
34
34
|
# rubocop:disable Gemspec/DevelopmentDependencies
|
35
|
+
gem.add_development_dependency("activejob", ">= 6.0")
|
35
36
|
gem.add_development_dependency("appraisal")
|
36
37
|
gem.add_development_dependency("database_cleaner")
|
38
|
+
gem.add_development_dependency("pry")
|
37
39
|
gem.add_development_dependency("rake")
|
38
40
|
gem.add_development_dependency("rr")
|
39
41
|
gem.add_development_dependency("rubocop")
|
40
42
|
gem.add_development_dependency("rubocop-rails")
|
41
43
|
gem.add_development_dependency("rubocop-rake")
|
42
|
-
gem.add_development_dependency("sqlite3"
|
44
|
+
gem.add_development_dependency("sqlite3")
|
43
45
|
# rubocop:enable Gemspec/DevelopmentDependencies
|
44
46
|
|
45
47
|
gem.description =
|
data/gemfiles/rails_6.0.gemfile
CHANGED
data/gemfiles/rails_6.1.gemfile
CHANGED
data/gemfiles/rails_7.0.gemfile
CHANGED
data/lib/archival_record.rb
CHANGED
@@ -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
|
-
|
11
|
-
|
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
|
@@ -41,10 +41,15 @@ module ArchivalRecordCore
|
|
41
41
|
end
|
42
42
|
|
43
43
|
private def setup_options(options)
|
44
|
-
default_options = {
|
44
|
+
default_options = {
|
45
|
+
readonly_when_archived: false,
|
46
|
+
archive_dependents: true,
|
47
|
+
raise_on_error: false
|
48
|
+
}
|
45
49
|
options.reverse_merge!(default_options)
|
46
50
|
|
47
51
|
define_method(:archive_dependents?) { options[:archive_dependents] }
|
52
|
+
define_method(:archival_raise_on_error?) { options[:raise_on_error] }
|
48
53
|
end
|
49
54
|
|
50
55
|
private def setup_validations(options)
|
@@ -53,11 +58,15 @@ module ArchivalRecordCore
|
|
53
58
|
end
|
54
59
|
|
55
60
|
private def setup_scopes
|
56
|
-
scope :archived, -> { where.not(
|
57
|
-
scope :unarchived, -> { where(
|
58
|
-
scope :archived_from_archive_number,
|
59
|
-
|
60
|
-
|
61
|
+
scope :archived, -> { where.not(archive_number: nil) }
|
62
|
+
scope :unarchived, -> { where(archive_number: nil) }
|
63
|
+
scope :archived_from_archive_number,
|
64
|
+
(lambda do |head_archive_number|
|
65
|
+
table = arel_table
|
66
|
+
archive_at_check = table[:archived_at].not_eq(nil)
|
67
|
+
archive_number_check = table[:archive_number].eq(head_archive_number)
|
68
|
+
where(archive_at_check.and(archive_number_check))
|
69
|
+
end)
|
61
70
|
end
|
62
71
|
|
63
72
|
private def setup_callbacks
|
@@ -83,6 +92,7 @@ module ArchivalRecordCore
|
|
83
92
|
private def define_callback_dsl_method(callbackable_type, action)
|
84
93
|
# rubocop:disable Security/Eval
|
85
94
|
eval <<-END_CALLBACKS, binding, __FILE__, __LINE__ + 1
|
95
|
+
# The below block gets turned into something like this:
|
86
96
|
# unless defined?(before_archive)
|
87
97
|
# def before_archive(*args, &blk)
|
88
98
|
# set_callback(:archive, :before, *args, &blk)
|
@@ -166,8 +176,11 @@ module ArchivalRecordCore
|
|
166
176
|
end
|
167
177
|
|
168
178
|
private def handle_archival_action_exception(exception)
|
169
|
-
|
170
|
-
|
179
|
+
ApplicationRecord.logger.try(:error, exception.message)
|
180
|
+
ApplicationRecord.logger.try(:error, exception.backtrace)
|
181
|
+
|
182
|
+
raise if archival_raise_on_error?
|
183
|
+
|
171
184
|
raise(ActiveRecord::Rollback)
|
172
185
|
end
|
173
186
|
|