undeletable 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/README.md +64 -0
- data/Rakefile +11 -0
- data/lib/undeletable.rb +57 -0
- data/lib/undeletable/version.rb +3 -0
- metadata +121 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ODZmMjIyMGQ4MzIyOTI0OWY5OTQ0ZmExYjBjYjYwY2YzYjIwZWJlOQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZjU0YzUyOTEwNDQ4OGRkNmZmNjk5ZDhjYjU1MmViZWMwYTcyMWJmYQ==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZjY1OGUzMmU0MTZhNmNkYWZlODMwNDY2YTM2YmE3YmRmZjcxMWJlODgxNGQ0
|
10
|
+
MTE4OGYyNTJhOTI3OGU0NzFkNjRhYmVmMTNlNmZkOWRkNzQ1YTMzY2I0ZjQ4
|
11
|
+
NTk5NjJmZDM0NjYwNzMzY2FhYmE3MjQyNTQ5YjYwMGQ2MTgxNTQ=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YmZmODYzZTRjMGMzNTUyNTQyM2ZlNTA0ODM5YzI4YmJmZjc5NDFjZmVkYTU3
|
14
|
+
NWE5ZWU3OGRiNjI2ZDg3M2YzOTdmOWEwYjc2ODZjYjBkYmEwN2I3NWZjODgw
|
15
|
+
NTk5MmUzNThhZGE5MjEwYzE3YjhlMGRhYWY3NDk2OWMzMzU5NGM=
|
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# Undeletable
|
2
|
+
|
3
|
+
The `undeletable` class method disables the ability to `delete`/`destroy` an ActiveRecord model instance, and `undeletable!` raises an error if a `delete`/`destroy!` is attempted. Can support destroy callbacks if raise not enabled.
|
4
|
+
|
5
|
+
Similar to paranoid/acts_as_paranoid, the bang methods, `destroy!` and `delete!` are provided in case the original destroy/delete methods are needed.
|
6
|
+
|
7
|
+
Undeletable is a fork of [Paranoia][paranoia] (by Ryan Bigg and others) but heavily modified to just disallow normal deletion.
|
8
|
+
|
9
|
+
## Installation & Usage
|
10
|
+
|
11
|
+
Put this in your Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'undeletable'
|
15
|
+
```
|
16
|
+
|
17
|
+
Then run:
|
18
|
+
|
19
|
+
```shell
|
20
|
+
bundle install
|
21
|
+
```
|
22
|
+
|
23
|
+
Updating is as simple as `bundle update undeletable`.
|
24
|
+
|
25
|
+
### Usage
|
26
|
+
|
27
|
+
#### In your environment.rb:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
Undeletable.configure do
|
31
|
+
# if true and with_raise not used, will debug log failed attempts to delete/destroy the models
|
32
|
+
self.debug = false
|
33
|
+
end
|
34
|
+
|
35
|
+
...
|
36
|
+
```
|
37
|
+
|
38
|
+
#### In your model:
|
39
|
+
|
40
|
+
To silently disallow attempts to delete/destroy:
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
class Client < ActiveRecord::Base
|
44
|
+
undeletable
|
45
|
+
|
46
|
+
...
|
47
|
+
end
|
48
|
+
```
|
49
|
+
|
50
|
+
To disallow attempts to delete/destroy, but raise ActiveRecord::ReadOnlyRecord on attempts:
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
class Client < ActiveRecord::Base
|
54
|
+
undeletable!
|
55
|
+
|
56
|
+
...
|
57
|
+
end
|
58
|
+
```
|
59
|
+
|
60
|
+
## License
|
61
|
+
|
62
|
+
This gem is released under the MIT license.
|
63
|
+
|
64
|
+
[paranoia]: https://github.com/radar/paranoia
|
data/Rakefile
ADDED
data/lib/undeletable.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'undeletable/version'
|
2
|
+
|
3
|
+
module Undeletable
|
4
|
+
class << self
|
5
|
+
attr_accessor :debug
|
6
|
+
def configure(&blk); class_eval(&blk); end
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.included(klazz)
|
10
|
+
klazz.extend Query
|
11
|
+
end
|
12
|
+
|
13
|
+
module Query
|
14
|
+
def undeletable? ; true ; end
|
15
|
+
end
|
16
|
+
|
17
|
+
def destroy
|
18
|
+
raise ActiveRecord::ReadOnlyRecord.new("#{self} is undeletable") if self.raise_on_delete
|
19
|
+
logger.debug("will not delete #{self}", e) if Undeletable.debug
|
20
|
+
run_callbacks(:destroy) { delete }
|
21
|
+
end
|
22
|
+
|
23
|
+
def delete
|
24
|
+
raise ActiveRecord::ReadOnlyRecord.new("#{self} is undeletable") if self.raise_on_delete
|
25
|
+
logger.debug("will not delete #{self}", e) if Undeletable.debug
|
26
|
+
end
|
27
|
+
|
28
|
+
# I'm hoping this won't fail checks!
|
29
|
+
#def destroyed?
|
30
|
+
#end
|
31
|
+
#alias :deleted? :destroyed?
|
32
|
+
end
|
33
|
+
|
34
|
+
Undeletable.configure do
|
35
|
+
self.debug = false
|
36
|
+
end
|
37
|
+
|
38
|
+
class ActiveRecord::Base
|
39
|
+
def self.undeletable(args = nil)
|
40
|
+
class_attribute :raise_on_delete, instance_writer: true
|
41
|
+
self.raise_on_delete = false
|
42
|
+
alias :destroy! :destroy
|
43
|
+
alias :delete! :delete
|
44
|
+
include Undeletable
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.undeletable!(args = nil)
|
48
|
+
class_attribute :raise_on_delete, instance_writer: true
|
49
|
+
self.raise_on_delete = true
|
50
|
+
alias :destroy! :destroy
|
51
|
+
alias :delete! :delete
|
52
|
+
include Undeletable
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.undeletable? ; false ; end
|
56
|
+
def undeletable? ; self.class.undeletable? ; end
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: undeletable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gary S. Weaver
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-04-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activerecord
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.0.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.0.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.0.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.0.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sqlite3
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.8.7
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.8.7
|
83
|
+
description: Ignores or raises error on destroy/delete of an ActiveRecord model instance,
|
84
|
+
but is not marked as read-only and can be created/updated. This is a significantly
|
85
|
+
modified fork of the Paranoia gem (by Ryan Bigg and others).
|
86
|
+
email:
|
87
|
+
- garysweaver@gmail.com
|
88
|
+
executables: []
|
89
|
+
extensions: []
|
90
|
+
extra_rdoc_files: []
|
91
|
+
files:
|
92
|
+
- lib/undeletable/version.rb
|
93
|
+
- lib/undeletable.rb
|
94
|
+
- Rakefile
|
95
|
+
- README.md
|
96
|
+
homepage: https://github.com/garysweaver/undeletable
|
97
|
+
licenses:
|
98
|
+
- MIT
|
99
|
+
metadata: {}
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ! '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ! '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: 1.3.6
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 2.0.3
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: Stop destroy/delete on certain ActiveRecord models without disallowing other
|
120
|
+
actions
|
121
|
+
test_files: []
|