oweb3_soft_delete 0.1.0
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 +52 -0
- data/Rakefile +37 -0
- data/lib/oweb3_soft_delete.rb +25 -0
- data/lib/oweb3_soft_delete/engine.rb +5 -0
- data/lib/oweb3_soft_delete/version.rb +3 -0
- data/lib/tasks/oweb3_soft_delete_tasks.rake +4 -0
- metadata +65 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b1b4d6cbfe917a0a63d16ccffa5986074cd46a27
|
4
|
+
data.tar.gz: 763440eb8180c3f4081d61cb15264c859c10b7e3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fb6787b04b444f18ba032485b019e3e10dce68b57462a350a85573cb3eceb7037b1d63ad74dee98b4894edf857271037f9f2870f029c0fdb1dd275045fe24db5
|
7
|
+
data.tar.gz: 1be20d68b779789ee7badee76dedd9cab252dc49fe0c04cfa11c3196a9fb50564c4b6cb403d2b94a7e82114b14f98d4250f243d7943ba7caa3475100b6010de7
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2017 Denis Fabien
|
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,52 @@
|
|
1
|
+
# Oweb3SoftDelete
|
2
|
+
Small gem to add soft delete feature to active record
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
How to use my plugin.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'oweb3_soft_delete'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle install
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
```bash
|
21
|
+
$ gem install oweb3_soft_delete
|
22
|
+
```
|
23
|
+
|
24
|
+
#### Adding migration to the model
|
25
|
+
```bash
|
26
|
+
rails g migration AddSoftDeletedToMyModel soft_deleted:datetime:index
|
27
|
+
```
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
#### In your model
|
31
|
+
|
32
|
+
To add a default_scope simply add acts_as_soft_delete
|
33
|
+
```bash
|
34
|
+
class MyModel < ActiveRecord::Base
|
35
|
+
acts_as_soft_delete
|
36
|
+
|
37
|
+
# ...
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
To soft delete and item :
|
42
|
+
```bash
|
43
|
+
my_model.oweb3_delete!
|
44
|
+
```
|
45
|
+
|
46
|
+
To find and undelete an item
|
47
|
+
```bash
|
48
|
+
MyModel.oweb3_deleted.find(1).oweb3_undelete!
|
49
|
+
```
|
50
|
+
|
51
|
+
## License
|
52
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
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 = 'Oweb3SoftDelete'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
load 'rails/tasks/statistics.rake'
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
require 'bundler/gem_tasks'
|
26
|
+
|
27
|
+
require 'rake/testtask'
|
28
|
+
|
29
|
+
Rake::TestTask.new(:test) do |t|
|
30
|
+
t.libs << 'lib'
|
31
|
+
t.libs << 'test'
|
32
|
+
t.pattern = 'test/**/*_test.rb'
|
33
|
+
t.verbose = false
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
task default: :test
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Oweb3SoftDelete
|
2
|
+
module ActiveRecord
|
3
|
+
def self.included(base)
|
4
|
+
end
|
5
|
+
|
6
|
+
def oweb3_delete!
|
7
|
+
self.update(soft_deleted: DateTime.now)
|
8
|
+
end
|
9
|
+
|
10
|
+
def oweb3_undelete!
|
11
|
+
self.update(soft_deleted: nil)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
ActiveSupport.on_load(:active_record) do
|
17
|
+
ActiveRecord::Base.send :include, Oweb3SoftDelete::ActiveRecord
|
18
|
+
def self.acts_as_soft_delete(options={})
|
19
|
+
default_scope {where({soft_deleted: nil})}
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.oweb3_deleted
|
23
|
+
self.unscoped
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: oweb3_soft_delete
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Denis Fabien
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-19 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: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Small gem to add soft delete feature to active record
|
28
|
+
email:
|
29
|
+
- denis.fabien.ca@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- MIT-LICENSE
|
35
|
+
- README.md
|
36
|
+
- Rakefile
|
37
|
+
- lib/oweb3_soft_delete.rb
|
38
|
+
- lib/oweb3_soft_delete/engine.rb
|
39
|
+
- lib/oweb3_soft_delete/version.rb
|
40
|
+
- lib/tasks/oweb3_soft_delete_tasks.rake
|
41
|
+
homepage: https://www.miseajour.net
|
42
|
+
licenses:
|
43
|
+
- MIT
|
44
|
+
metadata: {}
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 2.6.10
|
62
|
+
signing_key:
|
63
|
+
specification_version: 4
|
64
|
+
summary: Small gem to add soft delete feature to active record
|
65
|
+
test_files: []
|