never_wastes 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.md +53 -0
  2. data/lib/never_wastes/version.rb +1 -1
  3. metadata +2 -1
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # Never Wastes
2
+
3
+ Never Wastes adds soft delete to ActiveRecord.
4
+
5
+ It's similar to acts_as_paranoid but simpler.
6
+
7
+ ## Usage
8
+
9
+ First, add deleted column in your models.
10
+
11
+ class AddDeletedToYourModels < ActiveRecord::Migration
12
+ def change
13
+ add_column :your_models, :deleted, :boolean, :null => false, :default => false
14
+ end
15
+ end
16
+
17
+ Currently it supports boolean "deleted" column only.
18
+
19
+ Next step is to specify never_wastes in your model which needs soft delete.
20
+
21
+ class YourModel << ActiveRecord::Base
22
+ never_wastes
23
+ end
24
+
25
+ Then you can use destroy for soft delete.
26
+
27
+ model.destroy
28
+
29
+ If you want to hart delete, use destroy!.
30
+
31
+ model.destroy!
32
+
33
+ You can get non-deleted models by default.
34
+
35
+ models = YourModel.all # deleted models are not included
36
+
37
+ If you need to get models with deleted ones, you can use with_deleted.
38
+
39
+ models = YourModel.with_deleted.all
40
+
41
+ In your destroy callbacks, you can use softly_destroying? to check if you are in soft delete or hard delete.
42
+
43
+ after_destroy :delete_files
44
+ private
45
+ def delete_files
46
+ return if sortly_destroying?
47
+ # delete files associated with the model object
48
+ end
49
+
50
+ Use never_wastes? to check if a model supports soft delete or not.
51
+
52
+ YourModel.never_wastes?
53
+
@@ -1,3 +1,3 @@
1
1
  module NeverWastes
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: never_wastes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -21,6 +21,7 @@ extra_rdoc_files: []
21
21
  files:
22
22
  - .gitignore
23
23
  - Gemfile
24
+ - README.md
24
25
  - Rakefile
25
26
  - lib/never_wastes.rb
26
27
  - lib/never_wastes/version.rb