archival_record 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rubocop.yml +74 -0
- data/.rubocop_todo.yml +14 -0
- data/.travis.yml +23 -0
- data/Appraisals +18 -0
- data/CHANGELOG.md +96 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +69 -0
- data/LICENSE +56 -0
- data/README.md +209 -0
- data/Rakefile +16 -0
- data/archival_record.gemspec +51 -0
- data/gemfiles/rails_5.0.gemfile +8 -0
- data/gemfiles/rails_5.1.gemfile +8 -0
- data/gemfiles/rails_5.2.gemfile +8 -0
- data/gemfiles/rails_6.0.gemfile +7 -0
- data/init.rb +3 -0
- data/lib/archival_record.rb +19 -0
- data/lib/archival_record/version.rb +5 -0
- data/lib/archival_record_core/archival_record.rb +164 -0
- data/lib/archival_record_core/archival_record_active_record_methods.rb +45 -0
- data/lib/archival_record_core/association_operation/archive.rb +21 -0
- data/lib/archival_record_core/association_operation/base.rb +54 -0
- data/lib/archival_record_core/association_operation/unarchive.rb +17 -0
- data/script/setup +9 -0
- data/test/ambiguous_table_test.rb +16 -0
- data/test/application_record_test.rb +20 -0
- data/test/associations_test.rb +104 -0
- data/test/basic_test.rb +66 -0
- data/test/callbacks_test.rb +41 -0
- data/test/column_test.rb +17 -0
- data/test/deep_nesting_test.rb +35 -0
- data/test/deprecated_warning_archival_test.rb +11 -0
- data/test/fixtures/another_polys_holder.rb +11 -0
- data/test/fixtures/application_record.rb +5 -0
- data/test/fixtures/application_record_row.rb +8 -0
- data/test/fixtures/archival.rb +19 -0
- data/test/fixtures/archival_grandkid.rb +10 -0
- data/test/fixtures/archival_kid.rb +11 -0
- data/test/fixtures/archival_table_name.rb +10 -0
- data/test/fixtures/callback_archival_4.rb +19 -0
- data/test/fixtures/callback_archival_5.rb +23 -0
- data/test/fixtures/deprecated_warning_archival.rb +9 -0
- data/test/fixtures/exploder.rb +10 -0
- data/test/fixtures/independent_archival.rb +11 -0
- data/test/fixtures/missing_archive_number.rb +7 -0
- data/test/fixtures/missing_archived_at.rb +7 -0
- data/test/fixtures/plain.rb +7 -0
- data/test/fixtures/poly.rb +11 -0
- data/test/fixtures/readonly_when_archived.rb +8 -0
- data/test/polymorphic_test.rb +50 -0
- data/test/readonly_when_archived_test.rb +24 -0
- data/test/relations_test.rb +63 -0
- data/test/responds_test.rb +15 -0
- data/test/schema.rb +96 -0
- data/test/scope_test.rb +92 -0
- data/test/test_helper.rb +91 -0
- data/test/through_association_test.rb +27 -0
- data/test/transaction_test.rb +31 -0
- metadata +254 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 872aa8e89098dc62a3c40fb1053d8805bf5f030fc3a1fd5afbb650538d8b0b85
|
4
|
+
data.tar.gz: f8e64e5749c3bed043382924acaa9bacb456800d2be63f8dbc451bd7525716fa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7bc263147bcb996649a41d533da229fe0a7d6dcee2b7b8bdbd101dee5ccb20c3ea23cdc786e4f274a4ce4a8ec5f994f4770251d2ca8bc1dd677edbd9e88a564b
|
7
|
+
data.tar.gz: 1685b46aa236bd9feb1e3c6b6827cbdc71bb912323b216f81513e2060e78c7292dcb49072a8fede38a0fbeff09a1ca2da5e2beee777a89fb2adba16ea2f20928
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
Exclude:
|
5
|
+
- vendor/**/*
|
6
|
+
- gemfiles/**/*
|
7
|
+
TargetRubyVersion: 2.4
|
8
|
+
NewCops: enable
|
9
|
+
|
10
|
+
|
11
|
+
################
|
12
|
+
# Layout Rules #
|
13
|
+
################
|
14
|
+
Layout/EmptyLinesAroundClassBody:
|
15
|
+
EnforcedStyle: empty_lines_except_namespace
|
16
|
+
|
17
|
+
Layout/EmptyLinesAroundModuleBody:
|
18
|
+
EnforcedStyle: empty_lines_except_namespace
|
19
|
+
|
20
|
+
Layout/LineLength:
|
21
|
+
Max: 140
|
22
|
+
|
23
|
+
Layout/SpaceInsideHashLiteralBraces:
|
24
|
+
EnforcedStyle: space
|
25
|
+
|
26
|
+
|
27
|
+
################
|
28
|
+
# Code Metrics #
|
29
|
+
################
|
30
|
+
Metrics/BlockLength:
|
31
|
+
Exclude:
|
32
|
+
- 'test/schema.rb'
|
33
|
+
- '*.gemspec'
|
34
|
+
|
35
|
+
Metrics/AbcSize:
|
36
|
+
Max: 25
|
37
|
+
|
38
|
+
Metrics/MethodLength:
|
39
|
+
Max: 10
|
40
|
+
CountComments: false
|
41
|
+
|
42
|
+
|
43
|
+
###############
|
44
|
+
# Style Rules #
|
45
|
+
###############
|
46
|
+
Style/Alias:
|
47
|
+
EnforcedStyle: prefer_alias_method
|
48
|
+
|
49
|
+
# ¯\_(ツ)_/¯
|
50
|
+
# ʕノ•ᴥ•ʔノ ︵ ┻━┻
|
51
|
+
# ( ͡° ͜ʖ ͡°)
|
52
|
+
Style/AsciiComments:
|
53
|
+
Enabled: false
|
54
|
+
|
55
|
+
Style/Documentation:
|
56
|
+
Enabled: false
|
57
|
+
|
58
|
+
Style/DoubleNegation:
|
59
|
+
Enabled: false
|
60
|
+
|
61
|
+
Style/AccessModifierDeclarations:
|
62
|
+
Enabled: false
|
63
|
+
|
64
|
+
Style/FrozenStringLiteralComment:
|
65
|
+
EnforcedStyle: never
|
66
|
+
|
67
|
+
Style/HashSyntax:
|
68
|
+
EnforcedStyle: ruby19
|
69
|
+
|
70
|
+
Style/RaiseArgs:
|
71
|
+
EnforcedStyle: compact
|
72
|
+
|
73
|
+
Style/StringLiterals:
|
74
|
+
EnforcedStyle: double_quotes
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2020-08-03 13:04:37 -0400 using RuboCop version 0.82.0.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 7
|
10
|
+
# Cop supports --auto-correct.
|
11
|
+
Lint/SendWithMixinArgument:
|
12
|
+
Exclude:
|
13
|
+
- 'init.rb'
|
14
|
+
- 'lib/archival_record.rb'
|
data/.travis.yml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
language: ruby
|
2
|
+
cache: bundler
|
3
|
+
|
4
|
+
rvm:
|
5
|
+
- 2.4
|
6
|
+
- 2.5
|
7
|
+
- 2.6
|
8
|
+
- 2.7
|
9
|
+
|
10
|
+
gemfile:
|
11
|
+
- gemfiles/rails_5.0.gemfile
|
12
|
+
- gemfiles/rails_5.1.gemfile
|
13
|
+
- gemfiles/rails_5.2.gemfile
|
14
|
+
- gemfiles/rails_6.0.gemfile
|
15
|
+
|
16
|
+
before_install:
|
17
|
+
- gem update --system
|
18
|
+
|
19
|
+
matrix:
|
20
|
+
fast_finish: true
|
21
|
+
exclude:
|
22
|
+
- gemfile: gemfiles/rails_6.0.gemfile
|
23
|
+
rvm: 2.4
|
data/Appraisals
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
appraise "rails-5.0" do
|
2
|
+
gem "rails", "~> 5.0.0"
|
3
|
+
gem "sqlite3", "~> 1.3.13"
|
4
|
+
end
|
5
|
+
|
6
|
+
appraise "rails-5.1" do
|
7
|
+
gem "rails", "~> 5.1.0"
|
8
|
+
gem "sqlite3", "~> 1.4.1"
|
9
|
+
end
|
10
|
+
|
11
|
+
appraise "rails-5.2" do
|
12
|
+
gem "rails", "~> 5.2.0"
|
13
|
+
gem "sqlite3", "~> 1.4.1"
|
14
|
+
end
|
15
|
+
|
16
|
+
appraise "rails-6.0" do
|
17
|
+
gem "rails", "~> 6.0.0"
|
18
|
+
end
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
# CHANGELOG
|
2
|
+
|
3
|
+
|
4
|
+
## 2.0.0 – August 3, 2020
|
5
|
+
|
6
|
+
* **BREAKING CHANGE** Drop support for Rails 4.2
|
7
|
+
* **BREAKING CHANGE** Removed deprecated methods
|
8
|
+
* Fix Rails 6 deprecation warnings
|
9
|
+
* Renamed gem to [ArchivalRecord](https://github.com/janxious/archival_record/)
|
10
|
+
* `acts_as_archival` becomes `archival_record` in models with a deprecation warning.
|
11
|
+
|
12
|
+
-------
|
13
|
+
|
14
|
+
The Changelog below applies to versions of [ActsAsArchival](https://github.com/expectedbehavior/acts_as_archival/).
|
15
|
+
|
16
|
+
## 1.4.0 - July 10, 2019
|
17
|
+
* **BREAKING CHANGE** drop support for rails 4.1
|
18
|
+
* **BREAKING CHANGE** drop support for Ruby <2.4
|
19
|
+
* **BUGFIX** polymorphic associations that are archived/unarchived can be acted on safely if they share the same ID.
|
20
|
+
* add support officially for rails 5.2
|
21
|
+
* sqlite upgrades for various rails
|
22
|
+
* new methods `#archive_all!` and `#unarchive_all` that can be called off scopes
|
23
|
+
|
24
|
+
|
25
|
+
## 1.3.0 - October 21, 2017
|
26
|
+
* deprecate `#archive` and `#unarchive` in favor of `#archive!` and `#unarchive!` [#36](https://github.com/expectedbehavior/acts_as_archival/pull/36)
|
27
|
+
|
28
|
+
## 1.2.0 - March 19, 2017
|
29
|
+
* **BREAKING CHANGE** the utility instance and class method `is_archival?` is now `archival?`. `is_archival?` is deprecated and will be removed
|
30
|
+
* hard dependency on rails 4.1+ – this shouldn't break anything since it was de facto before, but worth mentioning
|
31
|
+
* minor refactoring through most code
|
32
|
+
* much work done to make automatic checks worthwhile (travis/rubocop)
|
33
|
+
* general test cleanup
|
34
|
+
* drop hard dependency on mysql and postresql in tests
|
35
|
+
|
36
|
+
## 1.1.1 - April 10, 2016
|
37
|
+
* Update the way the `::unarchived` scope is generated using `::not` instead of manually building SQL, which should be better for complex queries
|
38
|
+
|
39
|
+
## 1.1.0 - April 10, 2016
|
40
|
+
* **BREAKING CHANGE** obsolete mainline rails 3 and rails 4.0.x support because: they are EOL'ed for > 1y
|
41
|
+
* add rails 4.2 automated tests
|
42
|
+
* add rails 5 support
|
43
|
+
* test and document callbacks better - Thanks, Aaron Milam
|
44
|
+
* **BUGFIX** remove a bunch of deprecations
|
45
|
+
* **BUGFIX** improve compatibility with various new versions of software like mysql when testing
|
46
|
+
|
47
|
+
## 1.0.0 - April 5, 2016
|
48
|
+
* **BREAKING CHANGE** make `#archived?` return an actual boolean value
|
49
|
+
|
50
|
+
## 0.6.1 - July 24, 2014
|
51
|
+
* Fix deprecation warnings on Rails 4.1
|
52
|
+
* Test suite now runs against multiple versions of Rails
|
53
|
+
* Fully automated test suite setup
|
54
|
+
|
55
|
+
## 0.6.0 - April 14, 2014
|
56
|
+
* **BREAKING CHANGE** (possibly): Some refactoring to modern gem module idioms instead of old school plugins
|
57
|
+
* Officially support PostgreSQL
|
58
|
+
* Switch default testing to use sqlite, mysql, and postgres instead of just mysql
|
59
|
+
* Major upgrades to test suite
|
60
|
+
|
61
|
+
## 0.5.3 - May 17, 2013
|
62
|
+
* Major refactoring of archiving/unarchiving logic into nice command classes instead of big ball of ARec voodoo. Thanks, Marten Claes!
|
63
|
+
|
64
|
+
## 0.5.2
|
65
|
+
* **BREAKING CHANGE** (possibly): removed the scope constants, so if you were using them, you should stop
|
66
|
+
* **BUGFIX** fix scoping combinations with relations for Rails 4
|
67
|
+
* More changes to support Rails 4
|
68
|
+
|
69
|
+
## 0.5.1
|
70
|
+
* update to use .table_name for archived scope
|
71
|
+
|
72
|
+
## 0.5.0
|
73
|
+
* Rails 4.0.0b1 support. Thanks, James Hill!
|
74
|
+
|
75
|
+
## 0.4.5
|
76
|
+
* possibly allow rails 2&3 to work when dealing with associations
|
77
|
+
* add some logging when archive/unarchive doesn't work
|
78
|
+
|
79
|
+
## 0.4.4
|
80
|
+
* **BUGFIX** Callbacks were being called twice because of how we were defining them
|
81
|
+
|
82
|
+
## 0.4.3
|
83
|
+
* Fix spelling error
|
84
|
+
|
85
|
+
## 0.4.2
|
86
|
+
* Change homepage to the github repo
|
87
|
+
|
88
|
+
## 0.4.1
|
89
|
+
* remove explicit activesupport gem'ing
|
90
|
+
* update documentation for using plugin version with rails 3.0x
|
91
|
+
|
92
|
+
## 0.4.0
|
93
|
+
* **BUGFIX**: when `archive`/`unarchive` fail, they now return false instead of nil
|
94
|
+
* Rails 3.2 compatibility -- **Possibly Rails 3.0 incompatible due to ARec differences**
|
95
|
+
* Gemified!
|
96
|
+
* Super Duper Major test re-organization
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
archival_record (1.4.0)
|
5
|
+
activerecord (>= 5.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activemodel (6.0.3.2)
|
11
|
+
activesupport (= 6.0.3.2)
|
12
|
+
activerecord (6.0.3.2)
|
13
|
+
activemodel (= 6.0.3.2)
|
14
|
+
activesupport (= 6.0.3.2)
|
15
|
+
activesupport (6.0.3.2)
|
16
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
|
+
i18n (>= 0.7, < 2)
|
18
|
+
minitest (~> 5.1)
|
19
|
+
tzinfo (~> 1.1)
|
20
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
21
|
+
appraisal (2.2.0)
|
22
|
+
bundler
|
23
|
+
rake
|
24
|
+
thor (>= 0.14.0)
|
25
|
+
ast (2.4.0)
|
26
|
+
concurrent-ruby (1.1.6)
|
27
|
+
database_cleaner (1.8.4)
|
28
|
+
i18n (1.8.5)
|
29
|
+
concurrent-ruby (~> 1.0)
|
30
|
+
jaro_winkler (1.5.4)
|
31
|
+
minitest (5.14.1)
|
32
|
+
parallel (1.19.1)
|
33
|
+
parser (2.7.1.1)
|
34
|
+
ast (~> 2.4.0)
|
35
|
+
rainbow (3.0.0)
|
36
|
+
rake (13.0.1)
|
37
|
+
rexml (3.2.4)
|
38
|
+
rr (1.2.1)
|
39
|
+
rubocop (0.82.0)
|
40
|
+
jaro_winkler (~> 1.5.1)
|
41
|
+
parallel (~> 1.10)
|
42
|
+
parser (>= 2.7.0.1)
|
43
|
+
rainbow (>= 2.2.2, < 4.0)
|
44
|
+
rexml
|
45
|
+
ruby-progressbar (~> 1.7)
|
46
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
47
|
+
ruby-progressbar (1.10.1)
|
48
|
+
sqlite3 (1.4.2)
|
49
|
+
thor (1.0.1)
|
50
|
+
thread_safe (0.3.6)
|
51
|
+
tzinfo (1.2.7)
|
52
|
+
thread_safe (~> 0.1)
|
53
|
+
unicode-display_width (1.7.0)
|
54
|
+
zeitwerk (2.4.0)
|
55
|
+
|
56
|
+
PLATFORMS
|
57
|
+
ruby
|
58
|
+
|
59
|
+
DEPENDENCIES
|
60
|
+
appraisal
|
61
|
+
archival_record!
|
62
|
+
database_cleaner
|
63
|
+
rake
|
64
|
+
rr
|
65
|
+
rubocop (~> 0.82.0)
|
66
|
+
sqlite3
|
67
|
+
|
68
|
+
BUNDLED WITH
|
69
|
+
2.1.4
|
data/LICENSE
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
Copyright for portions of project ArchivalRecord are held by Expected Behavior, 2009-2020 as part of project ActsAsArchival. All other copyright for project ArchivalRecord are held by Joel Meador, 2020.
|
2
|
+
|
3
|
+
-----
|
4
|
+
|
5
|
+
LICENSE for [ArchivalRecord](https://github.com/janxious/archival_record/)
|
6
|
+
|
7
|
+
Copyright (c) 2020 Joel Meador
|
8
|
+
|
9
|
+
MIT License
|
10
|
+
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
12
|
+
a copy of this software and associated documentation files (the
|
13
|
+
"Software"), to deal in the Software without restriction, including
|
14
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
15
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
16
|
+
permit persons to whom the Software is furnished to do so, subject to
|
17
|
+
the following conditions:
|
18
|
+
|
19
|
+
The above copyright notice and this permission notice shall be
|
20
|
+
included in all copies or substantial portions of the Software.
|
21
|
+
|
22
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
23
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
24
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
25
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
26
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
27
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
28
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
29
|
+
|
30
|
+
|
31
|
+
-----
|
32
|
+
|
33
|
+
ORIGINAL LICENSE for [ActsAsArchival](https://github.com/expectedbehavior/acts_as_archival/)
|
34
|
+
|
35
|
+
Copyright (c) 2009-2013 Expected Behavior
|
36
|
+
|
37
|
+
MIT License
|
38
|
+
|
39
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
40
|
+
a copy of this software and associated documentation files (the
|
41
|
+
"Software"), to deal in the Software without restriction, including
|
42
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
43
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
44
|
+
permit persons to whom the Software is furnished to do so, subject to
|
45
|
+
the following conditions:
|
46
|
+
|
47
|
+
The above copyright notice and this permission notice shall be
|
48
|
+
included in all copies or substantial portions of the Software.
|
49
|
+
|
50
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
51
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
52
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
53
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
54
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
55
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
56
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,209 @@
|
|
1
|
+
# ArchivalRecord
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/janxious/archival_record.svg?branch=master)](https://travis-ci.org/janxious/archival_record)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/archival_record.svg)](https://badge.fury.io/rb/archival_record)
|
5
|
+
|
6
|
+
Atomically archive object trees in your ActiveRecord models.
|
7
|
+
|
8
|
+
`acts_as_paranoid` and similar plugins/gems work on a record-by-record basis and made it difficult to restore records atomically (or archive them, for that matter).
|
9
|
+
|
10
|
+
Because the `#archive!` and `#unarchive!` methods are in transactions, and every archival record involved gets the same archive number upon archiving, you can easily restore or remove an entire set of records without having to worry about partial deletion or restoration.
|
11
|
+
|
12
|
+
Additionally, other plugins generally change how `destroy`/`delete` work. ArchivalRecord does not, and thus one can destroy records like normal.
|
13
|
+
|
14
|
+
## Maintenance
|
15
|
+
|
16
|
+
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.
|
17
|
+
|
18
|
+
## Install
|
19
|
+
|
20
|
+
Gemfile:
|
21
|
+
|
22
|
+
`gem "archival_record"`
|
23
|
+
|
24
|
+
Any models you want to be archival should have the columns `archive_number` (String) and `archived_at` (DateTime).
|
25
|
+
|
26
|
+
i.e. `rails g migration AddArchivalRecordToPost archive_number archived_at:datetime`
|
27
|
+
|
28
|
+
Any dependent-destroy ArchivalRecord model associated to an ArchivalRecord model will be archived with its parent.
|
29
|
+
|
30
|
+
_If you're stuck on Rails 4.0x/3x/2x, check out the older tags/branches, which are no longer in active development._
|
31
|
+
|
32
|
+
## Example
|
33
|
+
|
34
|
+
``` ruby
|
35
|
+
class Hole < ActiveRecord::Base
|
36
|
+
archival_record
|
37
|
+
has_many :rats, dependent: :destroy
|
38
|
+
end
|
39
|
+
|
40
|
+
class Rat < ActiveRecord::Base
|
41
|
+
archival_record
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
### Simple interactions & scopes
|
46
|
+
|
47
|
+
``` ruby
|
48
|
+
h = Hole.create #
|
49
|
+
h.archived? # => false
|
50
|
+
h.archive! # => true
|
51
|
+
h.archived? # => true
|
52
|
+
h.archive_number # => "b56876de48a5dcfe71b2c13eec15e4a2"
|
53
|
+
h.archived_at # => Thu, 01 Jan 2012 01:49:21 -0400
|
54
|
+
h.unarchive! # => true
|
55
|
+
h.archived? # => false
|
56
|
+
h.archive_number # => nil
|
57
|
+
h.archived_at # => nil
|
58
|
+
```
|
59
|
+
|
60
|
+
### Associations
|
61
|
+
|
62
|
+
``` ruby
|
63
|
+
h = Hole.create #
|
64
|
+
r = h.rats.create #
|
65
|
+
h.archive! # => true
|
66
|
+
h.archive_number # => "b56876de48a5dcfe71b2c13eec15e4a2"
|
67
|
+
r.archived_at # => Thu, 01 Jan 2012 01:52:12 -0400
|
68
|
+
r.archived? # => true
|
69
|
+
h.unarchive! # => true
|
70
|
+
h.archive_number # => nil
|
71
|
+
r.archived_at # => nil
|
72
|
+
r.archived? # => false
|
73
|
+
```
|
74
|
+
|
75
|
+
### Relations
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
Hole.create!
|
79
|
+
Hole.create!
|
80
|
+
Hole.create!
|
81
|
+
|
82
|
+
holes = Hole.all
|
83
|
+
|
84
|
+
# All records in the relation will be archived with the same archive_number.
|
85
|
+
# Dependent/Destroy relationships will be archived, and callbacks will still be honored.
|
86
|
+
holes.archive_all! # => [array of Hole records in the relation]
|
87
|
+
|
88
|
+
holes.first.archive_number # => "b56876de48a5dcfe71b2c13eec15e4a2"
|
89
|
+
holes.last.archive_number # => "b56876de48a5dcfe71b2c13eec15e4a2"
|
90
|
+
|
91
|
+
holes.unarchive_all! # => [array of Hole records in the relation]
|
92
|
+
```
|
93
|
+
|
94
|
+
### Scopes
|
95
|
+
|
96
|
+
``` ruby
|
97
|
+
h = Hole.create
|
98
|
+
Hole.archived.size # => 0
|
99
|
+
Hole.unarchived.size # => 1
|
100
|
+
h.archive!
|
101
|
+
Hole.archived.size # => 1
|
102
|
+
Hole.unarchived.size # => 0
|
103
|
+
```
|
104
|
+
|
105
|
+
### Utility methods
|
106
|
+
|
107
|
+
``` ruby
|
108
|
+
h = Hole.create #
|
109
|
+
h.archival? # => true
|
110
|
+
Hole.archival? # => true
|
111
|
+
```
|
112
|
+
|
113
|
+
### Options
|
114
|
+
|
115
|
+
When defining an ArchivalRecord model, it is is possible to make it unmodifiable
|
116
|
+
when it is archived by passing `readonly_when_archived: true` to the
|
117
|
+
`archival_record` call in your model.
|
118
|
+
|
119
|
+
``` ruby
|
120
|
+
class CantTouchThis < ActiveRecord::Base
|
121
|
+
archival_record readonly_when_archived: true
|
122
|
+
end
|
123
|
+
|
124
|
+
record = CantTouchThis.create(foo: "bar")
|
125
|
+
record.archive! # => true
|
126
|
+
record.foo = "I want this to work"
|
127
|
+
record.save # => false
|
128
|
+
record.errors.full_messages.first # => "Cannot modify an archived record."
|
129
|
+
```
|
130
|
+
|
131
|
+
### Callbacks
|
132
|
+
|
133
|
+
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.
|
134
|
+
|
135
|
+
``` ruby
|
136
|
+
class Hole < ActiveRecord::Base
|
137
|
+
archival_record
|
138
|
+
|
139
|
+
# runs before #archive!
|
140
|
+
before_archive :some_method_before_archiving
|
141
|
+
|
142
|
+
# runs after #archive!
|
143
|
+
after_archive :some_method_after_archiving
|
144
|
+
|
145
|
+
# runs before #unarchive!
|
146
|
+
before_unarchive :some_method_before_unarchiving
|
147
|
+
|
148
|
+
# runs after #unarchive!
|
149
|
+
after_unarchive :some_method_after_unarchiving
|
150
|
+
|
151
|
+
# ... implement those methods
|
152
|
+
end
|
153
|
+
```
|
154
|
+
|
155
|
+
#### Halting the callback chain
|
156
|
+
|
157
|
+
* Rails 4.2 - the callback method should return a `false`/`nil` value.
|
158
|
+
* Rails 5.x - the callback should `throw(:abort)`/`raise(:abort)`.
|
159
|
+
|
160
|
+
## Caveats
|
161
|
+
|
162
|
+
1. This will only work on associations that are dependent destroy. It
|
163
|
+
should be trival to change that or make it optional.
|
164
|
+
1. If you would like to work on this, you will need to setup sqlite on your development machine. Alternately, you can disable specific dev dependencies in the gemspec and test_helper and ask for help.
|
165
|
+
|
166
|
+
## Testing
|
167
|
+
|
168
|
+
Running the tests should be as easy as:
|
169
|
+
|
170
|
+
``` bash
|
171
|
+
script/setup # bundles, makes databases with permissions
|
172
|
+
rake # run tests on latest Rails
|
173
|
+
appraisal rake # run tests on all versions of Rails
|
174
|
+
```
|
175
|
+
|
176
|
+
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.
|
177
|
+
|
178
|
+
## Help Wanted
|
179
|
+
|
180
|
+
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:
|
181
|
+
|
182
|
+
## Thanks
|
183
|
+
|
184
|
+
ActsAsParanoid and PermanentRecords were both inspirations for this:
|
185
|
+
|
186
|
+
* http://github.com/technoweenie/acts_as_paranoid
|
187
|
+
* http://github.com/fastestforward/permanent_records
|
188
|
+
|
189
|
+
## Contributors
|
190
|
+
|
191
|
+
* Joel Meador
|
192
|
+
* Michael Kuehl
|
193
|
+
* Matthew Gordon
|
194
|
+
* Vojtech Salbaba
|
195
|
+
* David Jones
|
196
|
+
* Dave Woodward
|
197
|
+
* Miles Sterrett
|
198
|
+
* James Hill
|
199
|
+
* Maarten Claes
|
200
|
+
* Anthony Panozzo
|
201
|
+
* Aaron Milam
|
202
|
+
* Anton Rieder
|
203
|
+
* Josh Menden
|
204
|
+
* Sergey Gnuskov
|
205
|
+
* Elijah Miller
|
206
|
+
|
207
|
+
Thanks!
|
208
|
+
|
209
|
+
[MIT-Licensed](LICENSE)
|