acts_as_paranoid 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +8 -5
- data/lib/acts_as_paranoid.rb +3 -0
- data/lib/acts_as_paranoid/core.rb +2 -2
- metadata +11 -6
data/README.markdown
CHANGED
@@ -186,29 +186,32 @@ Paranoiac.pretty.only_deleted.count #=> 1
|
|
186
186
|
Associations are also supported. From the simplest behaviors you'd expect to more nifty things like the ones mentioned previously or the usage of the `:with_deleted` option with `belongs_to`
|
187
187
|
|
188
188
|
```ruby
|
189
|
-
class
|
189
|
+
class Parent < ActiveRecord::Base
|
190
190
|
has_many :children, :class_name => "ParanoiacChild"
|
191
191
|
end
|
192
192
|
|
193
193
|
class ParanoiacChild < ActiveRecord::Base
|
194
|
-
belongs_to :parent
|
195
|
-
|
194
|
+
belongs_to :parent
|
195
|
+
belongs_to :parent_including_deleted, :class_name => "Parent", :with_deleted => true
|
196
|
+
# You cannot name association *_with_deleted
|
196
197
|
end
|
197
198
|
|
198
|
-
parent =
|
199
|
+
parent = Parent.first
|
199
200
|
child = parent.children.create
|
200
201
|
parent.destroy
|
201
202
|
|
202
203
|
child.parent #=> nil
|
203
|
-
child.
|
204
|
+
child.parent_including_deleted #=> Parent (it works!)
|
204
205
|
```
|
205
206
|
|
206
207
|
## Caveats
|
207
208
|
|
208
209
|
Watch out for these caveats:
|
209
210
|
|
211
|
+
|
210
212
|
- You cannot use scopes named `with_deleted` and `only_deleted`
|
211
213
|
- You cannot use scopes named `deleted_inside_time_window`, `deleted_before_time`, `deleted_after_time` **if** your paranoid column's type is `time`
|
214
|
+
- You cannot name association `*_with_deleted`
|
212
215
|
- `unscoped` will return all records, deleted or not
|
213
216
|
|
214
217
|
# Support
|
data/lib/acts_as_paranoid.rb
CHANGED
@@ -37,6 +37,9 @@ module ActsAsParanoid
|
|
37
37
|
# Magic!
|
38
38
|
default_scope { where(paranoid_default_scope_sql) }
|
39
39
|
|
40
|
+
# The paranoid column should not be mass-assignable
|
41
|
+
attr_protected paranoid_configuration[:column]
|
42
|
+
|
40
43
|
if paranoid_configuration[:column_type] == 'time'
|
41
44
|
scope :deleted_inside_time_window, lambda {|time, window|
|
42
45
|
deleted_after_time((time - window)).deleted_before_time((time + window))
|
@@ -94,7 +94,7 @@ module ActsAsParanoid
|
|
94
94
|
run_callbacks :destroy do
|
95
95
|
destroy_dependent_associations!
|
96
96
|
# Handle composite keys, otherwise we would just use `self.class.primary_key.to_sym => self.id`.
|
97
|
-
self.class.delete_all!(Hash[[Array(self.class.primary_key), Array(self.id)].transpose])
|
97
|
+
self.class.delete_all!(Hash[[Array(self.class.primary_key), Array(self.id)].transpose]) if persisted?
|
98
98
|
self.paranoid_value = self.class.delete_now_value
|
99
99
|
freeze
|
100
100
|
end
|
@@ -106,7 +106,7 @@ module ActsAsParanoid
|
|
106
106
|
with_transaction_returning_status do
|
107
107
|
run_callbacks :destroy do
|
108
108
|
# Handle composite keys, otherwise we would just use `self.class.primary_key.to_sym => self.id`.
|
109
|
-
self.class.delete_all(Hash[[Array(self.class.primary_key), Array(self.id)].transpose])
|
109
|
+
self.class.delete_all(Hash[[Array(self.class.primary_key), Array(self.id)].transpose]) if persisted?
|
110
110
|
self.paranoid_value = self.class.delete_now_value
|
111
111
|
self
|
112
112
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_paranoid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,11 +11,11 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2013-05-23 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activerecord
|
18
|
-
requirement:
|
18
|
+
requirement: !ruby/object:Gem::Requirement
|
19
19
|
none: false
|
20
20
|
requirements:
|
21
21
|
- - ~>
|
@@ -23,7 +23,12 @@ dependencies:
|
|
23
23
|
version: '3.2'
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
|
-
version_requirements:
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
none: false
|
28
|
+
requirements:
|
29
|
+
- - ~>
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: '3.2'
|
27
32
|
description: Active Record (~>3.2) plugin which allows you to hide and restore records
|
28
33
|
without actually deleting them. Check its GitHub page for more in-depth information.
|
29
34
|
email:
|
@@ -53,7 +58,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
53
58
|
version: '0'
|
54
59
|
segments:
|
55
60
|
- 0
|
56
|
-
hash:
|
61
|
+
hash: 713582617655354259
|
57
62
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
63
|
none: false
|
59
64
|
requirements:
|
@@ -62,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
62
67
|
version: 1.3.6
|
63
68
|
requirements: []
|
64
69
|
rubyforge_project: acts_as_paranoid
|
65
|
-
rubygems_version: 1.8.
|
70
|
+
rubygems_version: 1.8.25
|
66
71
|
signing_key:
|
67
72
|
specification_version: 3
|
68
73
|
summary: Active Record (~>3.2) plugin which allows you to hide and restore records
|