resurrection 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +82 -0
- data/Rakefile +26 -0
- data/lib/resurrection.rb +2 -0
- data/lib/resurrection/engine.rb +5 -0
- data/lib/resurrection/model.rb +61 -0
- data/lib/resurrection/version.rb +3 -0
- data/lib/tasks/resurrection_tasks.rake +4 -0
- metadata +137 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a9300ccdf386aa272f24b3ff5579d8fa3e15dee3
|
4
|
+
data.tar.gz: 93274339867b2e3ee98405db462572299bde1564
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d7404aa3936ffa7fd26e7df28a22fd8a73d5310efd22dcf3259a30860c23df98d1adb9dbd19dd528536d86b59bf4d1eba04d1a1ede82e0f5e04ccfe87e9c800c
|
7
|
+
data.tar.gz: 778d470a78033f6262e6560525b2e16761b581d25dce1b9ab626548a0a4f47af3a4f9d5b9d8081994e9c2efc786b0ca7ab0dedf2ea25c131cdca697ddad293fc
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2015 Nicholas Watson
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
# Resurrection
|
2
|
+
|
3
|
+
Christ died on a Friday, and rose again on Sunday. In honor of this feat, I present Resurrection. You can delete an object and bring it back to life. Simple as that.
|
4
|
+
|
5
|
+
# Installation
|
6
|
+
|
7
|
+
Add this line to your gemfile. I'm not adding this to rubygems. theres a million of these suckers out there. This one is mine with my own little tweaks. Feel free to use it.
|
8
|
+
|
9
|
+
```
|
10
|
+
gem 'resurrection', github: 'nwwatson/resurrection'
|
11
|
+
```
|
12
|
+
# Use
|
13
|
+
|
14
|
+
Okay, lets use this sucker. First we need to add a deleted_at field to our model.
|
15
|
+
|
16
|
+
```
|
17
|
+
bundle exec rails g migration add_column_deleted_at_to_jesuses deleted_at:datetime
|
18
|
+
```
|
19
|
+
|
20
|
+
|
21
|
+
All the work is done in a Concern. Yeah, I know, there are those that are against Concerns. I'm not. I don't like voodoo magic that appears when I don't expect it to (ie, adding it to ActiveRecord::Base). This simple include reminds me that I have the power to raise stuff from the dead
|
22
|
+
|
23
|
+
```
|
24
|
+
include Resurrection::Model
|
25
|
+
```
|
26
|
+
|
27
|
+
For those of you who are challenged, your model may look something like this....
|
28
|
+
|
29
|
+
```
|
30
|
+
class Jesus < ActiveRecord::Base
|
31
|
+
include Resurrection::Model
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
Jesus is my model. You can make your model whatever you want.
|
36
|
+
|
37
|
+
So lets delete something. I know what your thinking.... Why didn't you name it crucify? Well, I don't want to crucify things. Its a very painful death. I don't want to relive Passion of the Christ every time I delete an object. A simple delete will do for me.
|
38
|
+
|
39
|
+
```
|
40
|
+
my_model = Model.find(params[id])
|
41
|
+
my_model.delete
|
42
|
+
```
|
43
|
+
|
44
|
+
You can also use delete! if you are so include. If it makes you feel like your really deleting it with the "delete!", then use it. They both do the same thing.
|
45
|
+
|
46
|
+
Many gems add a default scope hiding deleted items from your view. I don't like this. Your model will have scopes in it to help you find records. The scopes are available and deleted. For example, if I want to view all non deleted files id do this:
|
47
|
+
|
48
|
+
```
|
49
|
+
Model.available
|
50
|
+
```
|
51
|
+
|
52
|
+
Likewise, I can find all deleted
|
53
|
+
|
54
|
+
```
|
55
|
+
Model.deleted
|
56
|
+
```
|
57
|
+
|
58
|
+
Okay, its time to resurrect something. I like that. Because Jesus made resurrection possible, I'm going to resurrect him.
|
59
|
+
|
60
|
+
```
|
61
|
+
jesus = Jesus.first
|
62
|
+
jesus.resurrect!
|
63
|
+
```
|
64
|
+
|
65
|
+
Noticed I used "ressurect!" I did this because its Jesus. If it wasn't him, i'm just call resurrect. They both do the same thing, but Jesus is special, and he deserves a bang at the end.
|
66
|
+
|
67
|
+
|
68
|
+
# Callback awesomeness
|
69
|
+
|
70
|
+
So you may want callbacks, such as after_delete, before_delete, and after_resurrection. They are there for the taking.
|
71
|
+
|
72
|
+
# Contributing
|
73
|
+
|
74
|
+
If you'd like to contribute a feature or bugfix: Thanks. To make sure your fix/feature has a high chance of being included, please read the following guidelines:
|
75
|
+
|
76
|
+
1. Post a [pull request](https://github.com/nwwatson/resurrection/compare/).
|
77
|
+
2. Make sure there are tests! It's a rare time when explicit tests aren't needed. If you have questions about writing tests for paperclip, please open a [GitHub issue](https://github.com/nwwatson/resurrection/issues/new).
|
78
|
+
|
79
|
+
|
80
|
+
# License
|
81
|
+
|
82
|
+
This rocks the MIT license. Live long an prosper.
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Resurrection'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
load 'rails/tasks/statistics.rake'
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
Bundler::GemHelper.install_tasks
|
26
|
+
|
data/lib/resurrection.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
module Resurrection
|
2
|
+
module Model
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
include ActiveSupport::Callbacks
|
7
|
+
scope :available, lambda { where(deleted_at: nil) }
|
8
|
+
scope :deleted, lambda { where("#{self.table_name}.deleted_at IS NOT NULL") }
|
9
|
+
|
10
|
+
# Define Deleted Callback
|
11
|
+
define_callbacks :deleted
|
12
|
+
set_callback :deleted, :after, :after_delete
|
13
|
+
|
14
|
+
# Define Resurrected Callback
|
15
|
+
define_callbacks :resurrected
|
16
|
+
set_callback :resurrected, :after, :after_resurrection
|
17
|
+
end
|
18
|
+
|
19
|
+
def delete
|
20
|
+
# if the record is new or destroyed, do nothing
|
21
|
+
return if new_record? or deleted?
|
22
|
+
|
23
|
+
# Calls before_delete callbacks before deletion takes place
|
24
|
+
run_callbacks :deleted do
|
25
|
+
update_attribute_or_column :deleted_at, Time.now
|
26
|
+
end
|
27
|
+
end
|
28
|
+
alias :delete! :delete
|
29
|
+
|
30
|
+
def resurrect
|
31
|
+
run_callbacks :resurrected do
|
32
|
+
update_attribute_or_column :deleted_at, nil
|
33
|
+
end
|
34
|
+
end
|
35
|
+
alias :resurrect! :resurrect
|
36
|
+
|
37
|
+
def deleted?
|
38
|
+
!self.deleted_at.nil?
|
39
|
+
end
|
40
|
+
|
41
|
+
def after_delete
|
42
|
+
return
|
43
|
+
end
|
44
|
+
|
45
|
+
def before_delete
|
46
|
+
return
|
47
|
+
end
|
48
|
+
|
49
|
+
def after_resurrection
|
50
|
+
return
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
# Rails 3.1 adds update_column. Rails > 3.2.6 deprecates update_attribute, gone in Rails 4.
|
56
|
+
def update_attribute_or_column(*args)
|
57
|
+
respond_to?(:update_attribute) ? update_attribute(*args) : update_column(*args)
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
metadata
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: resurrection
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nicholas Watson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-11-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec-rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.2.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.2.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec-its
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.1.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.1.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: shoulda-matchers
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.8.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.8.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: database_cleaner
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.4.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.4.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard-rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 4.5.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 4.5.0
|
97
|
+
description: A concern for models that follow ActiveModel::Model providing soft delete
|
98
|
+
functionality
|
99
|
+
email:
|
100
|
+
- nicholas.w.watson@icloud.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- MIT-LICENSE
|
106
|
+
- README.md
|
107
|
+
- Rakefile
|
108
|
+
- lib/resurrection.rb
|
109
|
+
- lib/resurrection/engine.rb
|
110
|
+
- lib/resurrection/model.rb
|
111
|
+
- lib/resurrection/version.rb
|
112
|
+
- lib/tasks/resurrection_tasks.rake
|
113
|
+
homepage: https://github.com/nwwatson/resurrection
|
114
|
+
licenses:
|
115
|
+
- MIT
|
116
|
+
metadata: {}
|
117
|
+
post_install_message:
|
118
|
+
rdoc_options: []
|
119
|
+
require_paths:
|
120
|
+
- lib
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
requirements: []
|
132
|
+
rubyforge_project:
|
133
|
+
rubygems_version: 2.5.2
|
134
|
+
signing_key:
|
135
|
+
specification_version: 4
|
136
|
+
summary: Resurrect models from the dead with ease
|
137
|
+
test_files: []
|