acts_as_archival 0.6.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -1
- data/README.md +32 -4
- data/acts_as_archival.gemspec +0 -2
- data/lib/acts_as_archival/version.rb +1 -1
- data/lib/expected_behavior/acts_as_archival.rb +1 -1
- data/test/basic_test.rb +2 -2
- metadata +3 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cff5862053f75da82a37e18eb5f014118fcc4702
|
4
|
+
data.tar.gz: a3289e80a677888517c5862d4905f2cbb44aad0f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 175eb9267a176e8047d4f23b6e5bd4c3c25e496f4ce4bcb61d61ccafd93ae5fddf2f6b9a9ece625a68bd76df83c82cb8e6b110ccec1ad958f37663aeeed11eba
|
7
|
+
data.tar.gz: f9abce355fe369749c02bf609ad2abfbfad7e482fb3393c3d12bdf9ef13b99fd80afdaa0ad83bcb9e512ae57f3527510d8279a4f8989f269a0b1a055fbdadf73
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -15,6 +15,10 @@ Additionally, other plugins generally screw with how
|
|
15
15
|
`destroy`/`delete` work. We don't because we actually want to be able
|
16
16
|
to destroy records.
|
17
17
|
|
18
|
+
## Maintenance
|
19
|
+
|
20
|
+
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.
|
21
|
+
|
18
22
|
## Install
|
19
23
|
|
20
24
|
Gemfile:
|
@@ -27,7 +31,7 @@ i.e. `rails g migration AddAAAToPost archive_number archived_at:datetime`
|
|
27
31
|
|
28
32
|
Any dependent-destroy AAA model associated to an AAA model will be archived with its parent.
|
29
33
|
|
30
|
-
_If you're stuck on Rails
|
34
|
+
_If you're stuck on Rails 3x/2x, check out the available branches, which are no longer in active development._
|
31
35
|
|
32
36
|
## Example
|
33
37
|
|
@@ -48,7 +52,7 @@ end
|
|
48
52
|
h = Hole.create #
|
49
53
|
h.archived? # => false
|
50
54
|
h.archive # => true
|
51
|
-
h.archived? # =>
|
55
|
+
h.archived? # => true
|
52
56
|
h.archive_number # => "b56876de48a5dcfe71b2c13eec15e4a2"
|
53
57
|
h.archived_at # => Thu, 01 Jan 2012 01:49:21 -0400
|
54
58
|
h.unarchive # => true
|
@@ -65,7 +69,7 @@ r = h.rats.create #
|
|
65
69
|
h.archive # => true
|
66
70
|
h.archive_number # => "b56876de48a5dcfe71b2c13eec15e4a2"
|
67
71
|
r.archive_number # => "b56876de48a5dcfe71b2c13eec15e4a2"
|
68
|
-
r.archived? # =>
|
72
|
+
r.archived? # => true
|
69
73
|
h.unarchive # => true
|
70
74
|
h.archive_number # => nil
|
71
75
|
r.archive_number # => nil
|
@@ -109,6 +113,30 @@ record.save # => false
|
|
109
113
|
record.errors.full_messages.first # => "Cannot modify an archived record."
|
110
114
|
```
|
111
115
|
|
116
|
+
### Callbacks
|
117
|
+
|
118
|
+
AAA 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.
|
119
|
+
|
120
|
+
``` ruby
|
121
|
+
class Hole < ActiveRecord::Base
|
122
|
+
acts_as_archival
|
123
|
+
|
124
|
+
before_archive :some_method_before_archiving
|
125
|
+
|
126
|
+
after_archive :some_method_after_archiving
|
127
|
+
|
128
|
+
before_unarchive :some_method_before_unarchiving
|
129
|
+
|
130
|
+
after_unarchive :some_method_before_unarchiving
|
131
|
+
|
132
|
+
# ... implement those methods
|
133
|
+
end
|
134
|
+
```
|
135
|
+
|
136
|
+
#### Halting the callback chain
|
137
|
+
|
138
|
+
The callback method should return a `false` value.
|
139
|
+
|
112
140
|
## Caveats
|
113
141
|
|
114
142
|
1. This will only work on associations that are dependent destroy. It
|
@@ -153,4 +181,4 @@ ActsAsParanoid and PermanentRecords were both inspirations for this:
|
|
153
181
|
|
154
182
|
Thanks!
|
155
183
|
|
156
|
-
*Copyright (c) 2009-
|
184
|
+
*Copyright (c) 2009-2016 Expected Behavior, LLC, released under the MIT license*
|
data/acts_as_archival.gemspec
CHANGED
@@ -16,10 +16,8 @@ Gem::Specification.new do |gem|
|
|
16
16
|
"James Hill",
|
17
17
|
"Maarten Claes"]
|
18
18
|
gem.email = ["joel@expectedbehavior.com",
|
19
|
-
"michael@expectedbehavior.com",
|
20
19
|
"matt@expectedbehavior.com",
|
21
20
|
"jason@expectedbehavior.com",
|
22
|
-
"tyler@expectedbehavior.com",
|
23
21
|
"nathan@expectedbehavior.com"]
|
24
22
|
gem.homepage = "http://github.com/expectedbehavior/acts_as_archival"
|
25
23
|
|
data/test/basic_test.rb
CHANGED
@@ -4,13 +4,13 @@ class BasicTest < ActiveSupport::TestCase
|
|
4
4
|
test "archive archives the record" do
|
5
5
|
archival = Archival.create!
|
6
6
|
archival.archive
|
7
|
-
|
7
|
+
assert_equal true, archival.reload.archived?
|
8
8
|
end
|
9
9
|
|
10
10
|
test "unarchive unarchives archival records" do
|
11
11
|
archival = Archival.create!(:archived_at => Time.now, :archive_number => 1)
|
12
12
|
archival.unarchive
|
13
|
-
|
13
|
+
assert_equal false, archival.reload.archived?
|
14
14
|
end
|
15
15
|
|
16
16
|
test "archive returns true on success" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_archival
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joel Meador
|
@@ -16,7 +16,7 @@ authors:
|
|
16
16
|
autorequire:
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
|
-
date:
|
19
|
+
date: 2016-04-05 00:00:00.000000000 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: activerecord
|
@@ -160,10 +160,8 @@ description: |
|
|
160
160
|
don't because we actually want to be able to destroy records.
|
161
161
|
email:
|
162
162
|
- joel@expectedbehavior.com
|
163
|
-
- michael@expectedbehavior.com
|
164
163
|
- matt@expectedbehavior.com
|
165
164
|
- jason@expectedbehavior.com
|
166
|
-
- tyler@expectedbehavior.com
|
167
165
|
- nathan@expectedbehavior.com
|
168
166
|
executables: []
|
169
167
|
extensions: []
|
@@ -240,7 +238,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
240
238
|
version: '0'
|
241
239
|
requirements: []
|
242
240
|
rubyforge_project:
|
243
|
-
rubygems_version: 2.
|
241
|
+
rubygems_version: 2.5.1
|
244
242
|
signing_key:
|
245
243
|
specification_version: 4
|
246
244
|
summary: Atomic archiving/unarchiving for ActiveRecord-based apps
|