never_wastes 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/lib/never_wastes.rb +59 -0
- data/lib/never_wastes/version.rb +3 -0
- data/never_wastes.gemspec +24 -0
- metadata +52 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/never_wastes.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require "never_wastes/version"
|
2
|
+
|
3
|
+
module NeverWastes
|
4
|
+
module Common
|
5
|
+
def self.included(base)
|
6
|
+
base.class_eval do
|
7
|
+
def self.never_wastes
|
8
|
+
include(NeverWastes::SoftDestroy)
|
9
|
+
end
|
10
|
+
def self.never_wastes?
|
11
|
+
include?(NeverWastes::SoftDestroy)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
def destroying_softly?
|
18
|
+
false
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
module SoftDestroy
|
23
|
+
def self.included(base)
|
24
|
+
base.class_eval do
|
25
|
+
alias_method :destroy!, :destroy
|
26
|
+
|
27
|
+
def destroy_softly
|
28
|
+
@destroying_softly = true
|
29
|
+
ret = with_transaction_returning_status do
|
30
|
+
run_callbacks :destroy do
|
31
|
+
self.class.where(self.class.primary_key.to_sym => id).update_all(:deleted => true)
|
32
|
+
self.deleted = true
|
33
|
+
@destroyed = true
|
34
|
+
freeze
|
35
|
+
end
|
36
|
+
end
|
37
|
+
@destroying_softly = nil
|
38
|
+
ret
|
39
|
+
end
|
40
|
+
alias_method :destroy, :destroy_softly
|
41
|
+
|
42
|
+
default_scope {where(:deleted => false)}
|
43
|
+
|
44
|
+
def self.with_deleted
|
45
|
+
unscoped
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
# useful in callbacks
|
50
|
+
def destroying_softly?
|
51
|
+
@destroying_softly
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
ActiveRecord::Base.send(:include, NeverWastes::Common)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "never_wastes/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "never_wastes"
|
7
|
+
s.version = NeverWastes::VERSION
|
8
|
+
s.authors = ["nay3"]
|
9
|
+
s.email = ["y.ohba@everyleaf.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{simple soft delete for ActiveRecord}
|
12
|
+
s.description = %q{It changes ActiveRecord::Base#destroy to support soft delete. Kind of simple acts_as_paranoid.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "never_wastes"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
# s.add_development_dependency "rspec"
|
23
|
+
# s.add_runtime_dependency "rest-client"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: never_wastes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- nay3
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-29 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: It changes ActiveRecord::Base#destroy to support soft delete. Kind of
|
15
|
+
simple acts_as_paranoid.
|
16
|
+
email:
|
17
|
+
- y.ohba@everyleaf.com
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- .gitignore
|
23
|
+
- Gemfile
|
24
|
+
- Rakefile
|
25
|
+
- lib/never_wastes.rb
|
26
|
+
- lib/never_wastes/version.rb
|
27
|
+
- never_wastes.gemspec
|
28
|
+
homepage: ''
|
29
|
+
licenses: []
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
requirements: []
|
47
|
+
rubyforge_project: never_wastes
|
48
|
+
rubygems_version: 1.8.17
|
49
|
+
signing_key:
|
50
|
+
specification_version: 3
|
51
|
+
summary: simple soft delete for ActiveRecord
|
52
|
+
test_files: []
|