acts_as_archival 1.1.1 → 2.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 +5 -5
- data/.gitignore +1 -1
- data/.rubocop.yml +71 -0
- data/.rubocop_todo.yml +98 -0
- data/.travis.yml +23 -0
- data/Appraisals +7 -7
- data/CHANGELOG.md +29 -0
- data/Gemfile.lock +70 -0
- data/README.md +49 -19
- data/Rakefile +6 -3
- data/acts_as_archival.gemspec +23 -17
- data/gemfiles/rails_5.2.gemfile +8 -0
- data/gemfiles/{rails_4.2.gemfile → rails_6.0.gemfile} +2 -2
- data/gemfiles/{rails_5.0.gemfile → rails_6.1.gemfile} +2 -2
- data/lib/acts_as_archival/version.rb +3 -1
- data/lib/acts_as_archival.rb +2 -0
- data/lib/expected_behavior/acts_as_archival.rb +111 -77
- data/lib/expected_behavior/acts_as_archival_active_record_methods.rb +29 -4
- data/lib/expected_behavior/association_operation/archive.rb +1 -1
- data/lib/expected_behavior/association_operation/base.rb +12 -9
- data/lib/expected_behavior/association_operation/unarchive.rb +2 -2
- data/script/setup +0 -3
- data/test/ambiguous_table_test.rb +3 -1
- data/test/application_record_test.rb +5 -3
- data/test/associations_test.rb +19 -17
- data/test/basic_test.rb +16 -14
- data/test/callbacks_test.rb +8 -6
- data/test/column_test.rb +8 -6
- data/test/deep_nesting_test.rb +6 -4
- data/test/fixtures/another_polys_holder.rb +11 -0
- data/test/fixtures/application_record.rb +2 -0
- data/test/fixtures/application_record_row.rb +2 -0
- data/test/fixtures/archival.rb +9 -7
- data/test/fixtures/archival_grandkid.rb +2 -0
- data/test/fixtures/archival_kid.rb +3 -1
- data/test/fixtures/archival_table_name.rb +2 -0
- data/test/fixtures/callback_archival_4.rb +2 -0
- data/test/fixtures/callback_archival_5.rb +4 -1
- data/test/fixtures/exploder.rb +2 -0
- data/test/fixtures/independent_archival.rb +2 -0
- data/test/fixtures/missing_archive_number.rb +2 -0
- data/test/fixtures/missing_archived_at.rb +2 -0
- data/test/fixtures/plain.rb +2 -0
- data/test/fixtures/poly.rb +3 -1
- data/test/fixtures/readonly_when_archived.rb +3 -1
- data/test/polymorphic_test.rb +29 -4
- data/test/readonly_when_archived_test.rb +6 -4
- data/test/relations_test.rb +63 -0
- data/test/responds_test.rb +8 -6
- data/test/schema.rb +64 -77
- data/test/scope_test.rb +28 -23
- data/test/test_helper.rb +47 -40
- data/test/through_association_test.rb +4 -2
- data/test/transaction_test.rb +7 -58
- metadata +33 -50
- data/gemfiles/rails_4.1.gemfile +0 -8
- data/script/db_setup +0 -51
- data/test/database.yml +0 -26
- data/test/fixtures/mass_attribute_protected.rb +0 -7
- data/test/fixtures/mysql_archival.rb +0 -10
- data/test/fixtures/mysql_exploder.rb +0 -9
- data/test/fixtures/pg_archival.rb +0 -10
- data/test/fixtures/pg_exploder.rb +0 -9
- data/test/mass_attribute_test.rb +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1f9de47af7c26b8d78744f6f150523da886cc3e72f3adfdf2c43489f92dd29d7
|
4
|
+
data.tar.gz: eb8710dc7dd90dfb876b83e61f9d08ac01003d734950f9554abd24d91e428875
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e16b3e95c07251f5f5c1dcd2b960e76ffc3f41241c7601b9cb7923e1f89bbc3c4aa21be46ad2b55ebce502933a3d6171ed1a57874857001a653db984822d8176
|
7
|
+
data.tar.gz: 9b818f82e6072dde8e0f7e1a621dd7593b918cb696738a0b1750b2357ab732250e18ae5d008813f3b8dc8204447df0f37e98561532343105c89682cd46a9a3c8
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1,71 @@
|
|
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/FrozenStringLiteralComment:
|
62
|
+
EnforcedStyle: never
|
63
|
+
|
64
|
+
Style/HashSyntax:
|
65
|
+
EnforcedStyle: ruby19
|
66
|
+
|
67
|
+
Style/RaiseArgs:
|
68
|
+
EnforcedStyle: compact
|
69
|
+
|
70
|
+
Style/StringLiterals:
|
71
|
+
EnforcedStyle: double_quotes
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2020-04-28 17:17:25 +0200 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: 2
|
10
|
+
# Cop supports --auto-correct.
|
11
|
+
Layout/EmptyLineAfterMagicComment:
|
12
|
+
Exclude:
|
13
|
+
- 'acts_as_archival.gemspec'
|
14
|
+
- 'test/scope_test.rb'
|
15
|
+
|
16
|
+
# Offense count: 1
|
17
|
+
# Cop supports --auto-correct.
|
18
|
+
# Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator.
|
19
|
+
# SupportedStylesForExponentOperator: space, no_space
|
20
|
+
Layout/SpaceAroundOperators:
|
21
|
+
Exclude:
|
22
|
+
- 'test/deep_nesting_test.rb'
|
23
|
+
|
24
|
+
# Offense count: 1
|
25
|
+
# Cop supports --auto-correct.
|
26
|
+
Lint/ScriptPermission:
|
27
|
+
Exclude:
|
28
|
+
- 'Rakefile'
|
29
|
+
|
30
|
+
# Offense count: 7
|
31
|
+
# Cop supports --auto-correct.
|
32
|
+
Lint/SendWithMixinArgument:
|
33
|
+
Exclude:
|
34
|
+
- 'init.rb'
|
35
|
+
- 'lib/acts_as_archival.rb'
|
36
|
+
|
37
|
+
# Offense count: 1
|
38
|
+
# Configuration parameters: EnforcedStyle.
|
39
|
+
# SupportedStyles: lowercase, uppercase
|
40
|
+
Naming/HeredocDelimiterCase:
|
41
|
+
Exclude:
|
42
|
+
- 'lib/expected_behavior/acts_as_archival.rb'
|
43
|
+
|
44
|
+
# Offense count: 3
|
45
|
+
# Configuration parameters: ForbiddenDelimiters.
|
46
|
+
# ForbiddenDelimiters: (?-mix:(^|\s)(EO[A-Z]{1}|END)(\s|$))
|
47
|
+
Naming/HeredocDelimiterNaming:
|
48
|
+
Exclude:
|
49
|
+
- 'acts_as_archival.gemspec'
|
50
|
+
- 'lib/expected_behavior/acts_as_archival.rb'
|
51
|
+
|
52
|
+
# Offense count: 12
|
53
|
+
# Configuration parameters: EnforcedStyle, AllowModifiersOnSymbols.
|
54
|
+
# SupportedStyles: inline, group
|
55
|
+
Style/AccessModifierDeclarations:
|
56
|
+
Exclude:
|
57
|
+
- 'lib/expected_behavior/acts_as_archival.rb'
|
58
|
+
- 'test/fixtures/callback_archival_4.rb'
|
59
|
+
- 'test/fixtures/callback_archival_5.rb'
|
60
|
+
|
61
|
+
# Offense count: 2
|
62
|
+
# Cop supports --auto-correct.
|
63
|
+
Style/Encoding:
|
64
|
+
Exclude:
|
65
|
+
- 'acts_as_archival.gemspec'
|
66
|
+
- 'test/scope_test.rb'
|
67
|
+
|
68
|
+
# Offense count: 1
|
69
|
+
Style/EvalWithLocation:
|
70
|
+
Exclude:
|
71
|
+
- 'lib/expected_behavior/acts_as_archival.rb'
|
72
|
+
|
73
|
+
# Offense count: 1
|
74
|
+
# Cop supports --auto-correct.
|
75
|
+
Style/ExpandPathArguments:
|
76
|
+
Exclude:
|
77
|
+
- 'acts_as_archival.gemspec'
|
78
|
+
|
79
|
+
# Offense count: 1
|
80
|
+
# Cop supports --auto-correct.
|
81
|
+
Style/IfUnlessModifier:
|
82
|
+
Exclude:
|
83
|
+
- 'test/test_helper.rb'
|
84
|
+
|
85
|
+
# Offense count: 1
|
86
|
+
# Cop supports --auto-correct.
|
87
|
+
# Configuration parameters: EnforcedStyle.
|
88
|
+
# SupportedStyles: implicit, explicit
|
89
|
+
Style/RescueStandardError:
|
90
|
+
Exclude:
|
91
|
+
- 'lib/expected_behavior/acts_as_archival.rb'
|
92
|
+
|
93
|
+
# Offense count: 3
|
94
|
+
# Cop supports --auto-correct.
|
95
|
+
# Configuration parameters: MinSize.
|
96
|
+
# SupportedStyles: percent, brackets
|
97
|
+
Style/SymbolArray:
|
98
|
+
EnforcedStyle: brackets
|
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
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
appraise "rails-
|
2
|
-
gem "rails", "~>
|
3
|
-
gem "
|
1
|
+
appraise "rails-5.2" do
|
2
|
+
gem "rails", "~> 5.2.0"
|
3
|
+
gem "sqlite3", "~> 1.4.1"
|
4
4
|
end
|
5
5
|
|
6
|
-
appraise "rails-
|
7
|
-
gem "rails", "~>
|
6
|
+
appraise "rails-6.0" do
|
7
|
+
gem "rails", "~> 6.0.0"
|
8
8
|
end
|
9
9
|
|
10
|
-
appraise "rails-
|
11
|
-
gem "rails", "~>
|
10
|
+
appraise "rails-6.1" do
|
11
|
+
gem "rails", "~> 6.1"
|
12
12
|
end
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,34 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 2.0.0 – (UNRELEASED)
|
4
|
+
|
5
|
+
* **BREAKING CHANGE** Drop support for Rails 4.2
|
6
|
+
* **BREAKING CHANGE** Drop support for Rails 5.0
|
7
|
+
* **BREAKING CHANGE** Drop support for Rails 5.1
|
8
|
+
* **BREAKING CHANGE** Removed deprecated methods
|
9
|
+
* Fix Rails 6 deprecation warnings
|
10
|
+
* Add offical support for Rails 6.1
|
11
|
+
|
12
|
+
## 1.4.0 - July 10, 2019
|
13
|
+
* **BREAKING CHANGE** drop support for rails 4.1
|
14
|
+
* **BREAKING CHANGE** drop support for Ruby <2.4
|
15
|
+
* **BUGFIX** polymorphic associations that are archived/unarchived can be acted on safely if they share the same ID.
|
16
|
+
* add support officially for rails 5.2
|
17
|
+
* sqlite upgrades for various rails
|
18
|
+
* new methods `#archive_all!` and `#unarchive_all` that can be called off scopes
|
19
|
+
|
20
|
+
|
21
|
+
## 1.3.0 - October 21, 2017
|
22
|
+
* deprecate `#archive` and `#unarchive` in favor of `#archive!` and `#unarchive!` [#36](https://github.com/expectedbehavior/acts_as_archival/pull/36)
|
23
|
+
|
24
|
+
## 1.2.0 - March 19, 2017
|
25
|
+
* **BREAKING CHANGE** the utility instance and class method `is_archival?` is now `archival?`. `is_archival?` is deprecated and will be removed
|
26
|
+
* hard dependency on rails 4.1+ – this shouldn't break anything since it was de facto before, but worth mentioning
|
27
|
+
* minor refactoring through most code
|
28
|
+
* much work done to make automatic checks worthwhile (travis/rubocop)
|
29
|
+
* general test cleanup
|
30
|
+
* drop hard dependency on mysql and postresql in tests
|
31
|
+
|
3
32
|
## 1.1.1 - April 10, 2016
|
4
33
|
* Update the way the `::unarchived` scope is generated using `::not` instead of manually building SQL, which should be better for complex queries
|
5
34
|
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
acts_as_archival (2.0.0)
|
5
|
+
activerecord (>= 5.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activemodel (6.1.4.1)
|
11
|
+
activesupport (= 6.1.4.1)
|
12
|
+
activerecord (6.1.4.1)
|
13
|
+
activemodel (= 6.1.4.1)
|
14
|
+
activesupport (= 6.1.4.1)
|
15
|
+
activesupport (6.1.4.1)
|
16
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
|
+
i18n (>= 1.6, < 2)
|
18
|
+
minitest (>= 5.1)
|
19
|
+
tzinfo (~> 2.0)
|
20
|
+
zeitwerk (~> 2.3)
|
21
|
+
appraisal (2.2.0)
|
22
|
+
bundler
|
23
|
+
rake
|
24
|
+
thor (>= 0.14.0)
|
25
|
+
assertions-eb (1.7.3)
|
26
|
+
ast (2.4.0)
|
27
|
+
concurrent-ruby (1.1.9)
|
28
|
+
database_cleaner (1.8.4)
|
29
|
+
i18n (1.8.10)
|
30
|
+
concurrent-ruby (~> 1.0)
|
31
|
+
jaro_winkler (1.5.4)
|
32
|
+
minitest (5.14.4)
|
33
|
+
parallel (1.19.1)
|
34
|
+
parser (2.7.1.1)
|
35
|
+
ast (~> 2.4.0)
|
36
|
+
rainbow (3.0.0)
|
37
|
+
rake (13.0.1)
|
38
|
+
rexml (3.2.4)
|
39
|
+
rr (1.2.1)
|
40
|
+
rubocop (0.82.0)
|
41
|
+
jaro_winkler (~> 1.5.1)
|
42
|
+
parallel (~> 1.10)
|
43
|
+
parser (>= 2.7.0.1)
|
44
|
+
rainbow (>= 2.2.2, < 4.0)
|
45
|
+
rexml
|
46
|
+
ruby-progressbar (~> 1.7)
|
47
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
48
|
+
ruby-progressbar (1.10.1)
|
49
|
+
sqlite3 (1.4.2)
|
50
|
+
thor (1.0.1)
|
51
|
+
tzinfo (2.0.4)
|
52
|
+
concurrent-ruby (~> 1.0)
|
53
|
+
unicode-display_width (1.7.0)
|
54
|
+
zeitwerk (2.4.2)
|
55
|
+
|
56
|
+
PLATFORMS
|
57
|
+
ruby
|
58
|
+
|
59
|
+
DEPENDENCIES
|
60
|
+
acts_as_archival!
|
61
|
+
appraisal
|
62
|
+
assertions-eb
|
63
|
+
database_cleaner
|
64
|
+
rake
|
65
|
+
rr
|
66
|
+
rubocop (~> 0.82.0)
|
67
|
+
sqlite3
|
68
|
+
|
69
|
+
BUNDLED WITH
|
70
|
+
2.1.4
|
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# ActsAsArchival
|
2
2
|
|
3
|
+
[](https://travis-ci.org/expectedbehavior/acts_as_archival)
|
4
|
+
[](https://badge.fury.io/rb/acts_as_archival)
|
5
|
+
|
3
6
|
Atomically archive object trees in your activerecord models.
|
4
7
|
|
5
8
|
We had the problem that acts_as_paranoid and similar plugins/gems
|
@@ -38,7 +41,7 @@ _If you're stuck on Rails 4.0x/3x/2x, check out the older tags/branches, which a
|
|
38
41
|
``` ruby
|
39
42
|
class Hole < ActiveRecord::Base
|
40
43
|
acts_as_archival
|
41
|
-
has_many :rats, :
|
44
|
+
has_many :rats, dependent: :destroy
|
42
45
|
end
|
43
46
|
|
44
47
|
class Rat < ActiveRecord::Base
|
@@ -51,11 +54,11 @@ end
|
|
51
54
|
``` ruby
|
52
55
|
h = Hole.create #
|
53
56
|
h.archived? # => false
|
54
|
-
h.archive
|
57
|
+
h.archive! # => true
|
55
58
|
h.archived? # => true
|
56
59
|
h.archive_number # => "b56876de48a5dcfe71b2c13eec15e4a2"
|
57
60
|
h.archived_at # => Thu, 01 Jan 2012 01:49:21 -0400
|
58
|
-
h.unarchive
|
61
|
+
h.unarchive! # => true
|
59
62
|
h.archived? # => false
|
60
63
|
h.archive_number # => nil
|
61
64
|
h.archived_at # => nil
|
@@ -66,23 +69,42 @@ h.archived_at # => nil
|
|
66
69
|
``` ruby
|
67
70
|
h = Hole.create #
|
68
71
|
r = h.rats.create #
|
69
|
-
h.archive
|
72
|
+
h.archive! # => true
|
70
73
|
h.archive_number # => "b56876de48a5dcfe71b2c13eec15e4a2"
|
71
|
-
r.
|
74
|
+
r.archived_at # => Thu, 01 Jan 2012 01:52:12 -0400
|
72
75
|
r.archived? # => true
|
73
|
-
h.unarchive
|
76
|
+
h.unarchive! # => true
|
74
77
|
h.archive_number # => nil
|
75
|
-
r.
|
78
|
+
r.archived_at # => nil
|
76
79
|
r.archived? # => false
|
77
80
|
```
|
78
81
|
|
82
|
+
### Relations
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
Hole.create!
|
86
|
+
Hole.create!
|
87
|
+
Hole.create!
|
88
|
+
|
89
|
+
holes = Hole.all
|
90
|
+
|
91
|
+
# All records in the relation will be archived with the same archive_number.
|
92
|
+
# Dependent/Destroy relationships will be archived, and callbacks will still be honored.
|
93
|
+
holes.archive_all! # => [array of Hole records in the relation]
|
94
|
+
|
95
|
+
holes.first.archive_number # => "b56876de48a5dcfe71b2c13eec15e4a2"
|
96
|
+
holes.last.archive_number # => "b56876de48a5dcfe71b2c13eec15e4a2"
|
97
|
+
|
98
|
+
holes.unarchive_all! # => [array of Hole records in the relation]
|
99
|
+
```
|
100
|
+
|
79
101
|
### Scopes
|
80
102
|
|
81
103
|
``` ruby
|
82
104
|
h = Hole.create
|
83
105
|
Hole.archived.size # => 0
|
84
106
|
Hole.unarchived.size # => 1
|
85
|
-
h.archive
|
107
|
+
h.archive!
|
86
108
|
Hole.archived.size # => 1
|
87
109
|
Hole.unarchived.size # => 0
|
88
110
|
```
|
@@ -91,23 +113,23 @@ Hole.unarchived.size # => 0
|
|
91
113
|
|
92
114
|
``` ruby
|
93
115
|
h = Hole.create #
|
94
|
-
h.
|
95
|
-
Hole.
|
116
|
+
h.archival? # => true
|
117
|
+
Hole.archival? # => true
|
96
118
|
```
|
97
119
|
|
98
120
|
### Options
|
99
121
|
|
100
122
|
When defining an AAA model, it is is possible to make it unmodifiable
|
101
|
-
when it is archived by passing
|
123
|
+
when it is archived by passing `readonly_when_archived: true` to the
|
102
124
|
`acts_as_archival` call in your model.
|
103
125
|
|
104
126
|
``` ruby
|
105
127
|
class CantTouchThis < ActiveRecord::Base
|
106
|
-
acts_as_archival :
|
128
|
+
acts_as_archival readonly_when_archived: true
|
107
129
|
end
|
108
130
|
|
109
|
-
record = CantTouchThis.create(:
|
110
|
-
record.archive
|
131
|
+
record = CantTouchThis.create(foo: "bar")
|
132
|
+
record.archive! # => true
|
111
133
|
record.foo = "I want this to work"
|
112
134
|
record.save # => false
|
113
135
|
record.errors.full_messages.first # => "Cannot modify an archived record."
|
@@ -121,13 +143,17 @@ AAA models have four additional callbacks to do any necessary cleanup or other p
|
|
121
143
|
class Hole < ActiveRecord::Base
|
122
144
|
acts_as_archival
|
123
145
|
|
146
|
+
# runs before #archive!
|
124
147
|
before_archive :some_method_before_archiving
|
125
148
|
|
149
|
+
# runs after #archive!
|
126
150
|
after_archive :some_method_after_archiving
|
127
151
|
|
152
|
+
# runs before #unarchive!
|
128
153
|
before_unarchive :some_method_before_unarchiving
|
129
154
|
|
130
|
-
|
155
|
+
# runs after #unarchive!
|
156
|
+
after_unarchive :some_method_after_unarchiving
|
131
157
|
|
132
158
|
# ... implement those methods
|
133
159
|
end
|
@@ -135,14 +161,14 @@ end
|
|
135
161
|
|
136
162
|
#### Halting the callback chain
|
137
163
|
|
138
|
-
* Rails 4.
|
139
|
-
* Rails
|
164
|
+
* Rails 4.2 - the callback method should return a `false`/`nil` value.
|
165
|
+
* Rails 5.x - the callback should `throw(:abort)`/`raise(:abort)`.
|
140
166
|
|
141
167
|
## Caveats
|
142
168
|
|
143
169
|
1. This will only work on associations that are dependent destroy. It
|
144
170
|
should be trival to change that or make it optional.
|
145
|
-
1. If you would like to work on this, you will need to setup sqlite
|
171
|
+
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.
|
146
172
|
|
147
173
|
## Testing
|
148
174
|
|
@@ -178,8 +204,12 @@ ActsAsParanoid and PermanentRecords were both inspirations for this:
|
|
178
204
|
* Miles Sterrett
|
179
205
|
* James Hill
|
180
206
|
* Maarten Claes
|
207
|
+
* Anthony Panozzo
|
181
208
|
* Aaron Milam
|
209
|
+
* Anton Rieder
|
210
|
+
* Josh Menden
|
211
|
+
* Sergey Gnuskov
|
182
212
|
|
183
213
|
Thanks!
|
184
214
|
|
185
|
-
*Copyright (c) 2009-
|
215
|
+
*Copyright (c) 2009-2017 Expected Behavior, LLC, released under the MIT license*
|
data/Rakefile
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
2
|
require "bundler/gem_tasks"
|
3
3
|
require "rake/testtask"
|
4
|
+
require "rubocop/rake_task"
|
4
5
|
|
5
|
-
|
6
|
-
|
6
|
+
RuboCop::RakeTask.new
|
7
|
+
|
8
|
+
desc "Default: run all available test suites."
|
9
|
+
task default: [:rubocop, :test]
|
7
10
|
|
8
11
|
desc "Test the acts_as_archival plugin."
|
9
12
|
Rake::TestTask.new(:test) do |t|
|
10
|
-
t.libs
|
13
|
+
t.libs << "test"
|
11
14
|
t.pattern = "test/**/*_test.rb"
|
12
15
|
t.verbose = true
|
13
16
|
end
|
data/acts_as_archival.gemspec
CHANGED
@@ -4,7 +4,7 @@ require "acts_as_archival/version"
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |gem|
|
6
6
|
gem.name = "acts_as_archival"
|
7
|
-
gem.summary =
|
7
|
+
gem.summary = "Atomic archiving/unarchiving for ActiveRecord-based apps"
|
8
8
|
gem.version = ActsAsArchival::VERSION
|
9
9
|
gem.authors = ["Joel Meador",
|
10
10
|
"Michael Kuehl",
|
@@ -14,7 +14,12 @@ Gem::Specification.new do |gem|
|
|
14
14
|
"Dave Woodward",
|
15
15
|
"Miles Sterrett",
|
16
16
|
"James Hill",
|
17
|
-
"Maarten Claes"
|
17
|
+
"Maarten Claes",
|
18
|
+
"Anthony Panozzo",
|
19
|
+
"Aaron Milam",
|
20
|
+
"Anton Rieder",
|
21
|
+
"Josh Menden",
|
22
|
+
"Sergey Gnuskov"]
|
18
23
|
gem.email = ["joel@expectedbehavior.com",
|
19
24
|
"matt@expectedbehavior.com",
|
20
25
|
"jason@expectedbehavior.com",
|
@@ -24,31 +29,32 @@ Gem::Specification.new do |gem|
|
|
24
29
|
gem.files = `git ls-files`.split("\n")
|
25
30
|
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
26
31
|
gem.require_paths = ["lib"]
|
32
|
+
gem.required_ruby_version = ">= 2.4"
|
27
33
|
|
28
|
-
gem.add_dependency "activerecord"
|
34
|
+
gem.add_dependency "activerecord", ">= 5.0"
|
29
35
|
|
30
36
|
gem.add_development_dependency "appraisal"
|
31
37
|
gem.add_development_dependency "assertions-eb"
|
32
38
|
gem.add_development_dependency "database_cleaner"
|
33
|
-
gem.add_development_dependency "mysql2"
|
34
|
-
gem.add_development_dependency "pg"
|
35
39
|
gem.add_development_dependency "rake"
|
36
40
|
gem.add_development_dependency "rr"
|
41
|
+
gem.add_development_dependency "rubocop", "~> 0.82.0"
|
37
42
|
gem.add_development_dependency "sqlite3"
|
38
43
|
|
39
|
-
gem.description =
|
40
|
-
|
44
|
+
gem.description =
|
45
|
+
<<~END
|
46
|
+
*Atomic archiving/unarchiving for ActiveRecord-based apps*
|
41
47
|
|
42
|
-
We had the problem that acts_as_paranoid and similar plugins/gems always work on
|
43
|
-
a record by record basis and made it very difficult to restore records
|
44
|
-
atomically (or archive them, for that matter).
|
48
|
+
We had the problem that acts_as_paranoid and similar plugins/gems always work on
|
49
|
+
a record by record basis and made it very difficult to restore records
|
50
|
+
atomically (or archive them, for that matter).
|
45
51
|
|
46
|
-
Because the archive and unarchive methods are in transactions, and every
|
47
|
-
archival record involved gets the same archive number upon archiving, you can
|
48
|
-
easily restore or remove an entire set of records without having to worry about
|
49
|
-
partial deletion or restoration.
|
52
|
+
Because the archive and unarchive methods are in transactions, and every
|
53
|
+
archival record involved gets the same archive number upon archiving, you can
|
54
|
+
easily restore or remove an entire set of records without having to worry about
|
55
|
+
partial deletion or restoration.
|
50
56
|
|
51
|
-
Additionally, other plugins generally screw with how destroy/delete work.
|
52
|
-
don't because we actually want to be able to destroy records.
|
53
|
-
END
|
57
|
+
Additionally, other plugins generally screw with how destroy/delete work. We
|
58
|
+
don't because we actually want to be able to destroy records.
|
59
|
+
END
|
54
60
|
end
|
data/lib/acts_as_archival.rb
CHANGED
@@ -15,3 +15,5 @@ else
|
|
15
15
|
ActiveRecord::Base.send :include, ExpectedBehavior::ActsAsArchival
|
16
16
|
ActiveRecord::Base.send :include, ExpectedBehavior::ActsAsArchivalActiveRecordMethods
|
17
17
|
end
|
18
|
+
|
19
|
+
ActiveRecord::Relation.send :include, ExpectedBehavior::ActsAsArchivalActiveRecordMethods::ARRelationMethods
|