false_destroy 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +0 -0
- data/README.md +40 -0
- data/Rakefile +57 -0
- data/VERSION +1 -0
- data/lib/false_destroy.rb +46 -0
- data/lib/version.rb +4 -0
- metadata +74 -0
data/LICENSE.txt
ADDED
File without changes
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
false_destroy
|
2
|
+
======================
|
3
|
+
|
4
|
+
when mark a record deleted in DB, eg: 0 is not deleted, 1 is deleted
|
5
|
+
|
6
|
+
we can call `false_destroy`,then will run callback after_false_destroy like after_destroy in rails.
|
7
|
+
|
8
|
+
## Install
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem "false_destroy", "0.1.0"
|
12
|
+
```
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
class Orgunit < ActiveRecord::Base
|
18
|
+
after_false_destroy do
|
19
|
+
# do blabla
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
orgunit = Orgunit.first
|
24
|
+
orgunit.false_destroy
|
25
|
+
```
|
26
|
+
|
27
|
+
## Config
|
28
|
+
|
29
|
+
you can config DB column_name and when_name as the db column name
|
30
|
+
|
31
|
+
column_name: destroyed mark column, default named deleted
|
32
|
+
|
33
|
+
when_name: false destroy time, default named deleted_at
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
FalseDestroy.column_name = 'destroyed'
|
37
|
+
FalseDestroy.when_name = 'destroyed_at'
|
38
|
+
```
|
39
|
+
|
40
|
+
That's ALL, Enjoy it!!!
|
data/Rakefile
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require 'active_model'
|
4
|
+
require 'active_record'
|
5
|
+
require 'rails'
|
6
|
+
require 'false_destroy'
|
7
|
+
|
8
|
+
begin
|
9
|
+
require 'bundler/setup'
|
10
|
+
rescue LoadError
|
11
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
12
|
+
end
|
13
|
+
begin
|
14
|
+
require 'rdoc/task'
|
15
|
+
rescue LoadError
|
16
|
+
require 'rdoc/rdoc'
|
17
|
+
require 'rake/rdoctask'
|
18
|
+
RDoc::Task = Rake::RDocTask
|
19
|
+
end
|
20
|
+
|
21
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
22
|
+
rdoc.rdoc_dir = 'rdoc'
|
23
|
+
rdoc.title = 'FalseDestroy'
|
24
|
+
rdoc.options << '--line-numbers'
|
25
|
+
rdoc.rdoc_files.include('README.md')
|
26
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
27
|
+
end
|
28
|
+
|
29
|
+
# Bundler::GemHelper.install_tasks
|
30
|
+
|
31
|
+
require 'rake/testtask'
|
32
|
+
|
33
|
+
Rake::TestTask.new(:spec) do |t|
|
34
|
+
t.libs << 'lib'
|
35
|
+
t.libs << 'spec'
|
36
|
+
t.pattern = 'sepc/**/*_spec.rb'
|
37
|
+
t.verbose = false
|
38
|
+
end
|
39
|
+
|
40
|
+
task :build do
|
41
|
+
system "gem build false_destroy.gemspec"
|
42
|
+
end
|
43
|
+
|
44
|
+
task :install => :build do
|
45
|
+
system "gem install false_destroy-#{FalseDestroy::VERSION}.gem"
|
46
|
+
end
|
47
|
+
|
48
|
+
task :release => :build do
|
49
|
+
puts "Tagging #{FalseDestroy::VERSION}..."
|
50
|
+
system "git tag -a #{FalseDestroy::VERSION} -m 'Tagging #{FalseDestroy::VERSION}'"
|
51
|
+
puts "Pushing to Github..."
|
52
|
+
system "git push --tags"
|
53
|
+
puts "Pushing to rubygems.org..."
|
54
|
+
system "gem push false_destroy-#{FalseDestroy::VERSION}.gem"
|
55
|
+
end
|
56
|
+
|
57
|
+
task :default => :spec
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,46 @@
|
|
1
|
+
#encoding:utf-8
|
2
|
+
require 'version'
|
3
|
+
|
4
|
+
module FalseDestroy
|
5
|
+
|
6
|
+
mattr_accessor :column_name
|
7
|
+
self.column_name = 'deleted'
|
8
|
+
mattr_accessor :when_name
|
9
|
+
self.when_name = 'deleted_at'
|
10
|
+
|
11
|
+
module Callbacks
|
12
|
+
def self.included(base)
|
13
|
+
base.extend ClassMethods
|
14
|
+
base.class_eval {
|
15
|
+
include InstanceMethods
|
16
|
+
define_model_callbacks :false_destroy, :only => :after
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
module ClassMethods
|
21
|
+
# Nothing
|
22
|
+
end
|
23
|
+
|
24
|
+
module InstanceMethods
|
25
|
+
def false_destroy
|
26
|
+
name = FalseDestroy.column_name
|
27
|
+
_when = FalseDestroy.when_name
|
28
|
+
self.send("#{name}=",true) if self.respond_to? name
|
29
|
+
self.send("#{_when}=",Time.now) if self.respond_to? _when
|
30
|
+
self.save
|
31
|
+
run_callbacks :false_destroy
|
32
|
+
end
|
33
|
+
|
34
|
+
def false_destroy!
|
35
|
+
name = FalseDestroy.column_name
|
36
|
+
_when = FalseDestroy.when_name
|
37
|
+
self.send("#{name}=",true) if self.respond_to? name
|
38
|
+
self.send("#{_when}=",Time.now) if self.respond_to? _when
|
39
|
+
self.save!
|
40
|
+
run_callbacks :false_destroy
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
ActiveRecord::Base.send :include, FalseDestroy::Callbacks
|
data/lib/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: false_destroy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- wxianfeng
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: when mark a record deleted in DB, then run callback after_false_destroy
|
31
|
+
like after_destroy in rails
|
32
|
+
email:
|
33
|
+
- wang.fl1429@gmail.com
|
34
|
+
executables: []
|
35
|
+
extensions: []
|
36
|
+
extra_rdoc_files: []
|
37
|
+
files:
|
38
|
+
- README.md
|
39
|
+
- VERSION
|
40
|
+
- LICENSE.txt
|
41
|
+
- Rakefile
|
42
|
+
- lib/false_destroy.rb
|
43
|
+
- lib/version.rb
|
44
|
+
homepage: http://github.com/wxianfeng/false_destroy
|
45
|
+
licenses: []
|
46
|
+
post_install_message: ! " false_destroy is a tool for ActiveRecord callback.\n when
|
47
|
+
mark a record deleted in DB, then run callback after_false_destroy like after_destroy
|
48
|
+
in rails, writen in Ruby.\n \n http://github.com/wxianfeng/false_destroy\n\n Enjoy!\n\n
|
49
|
+
\ wxianfeng (wang.fl1429@gmail.com)\n\n"
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
hash: 2836972165828198916
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ! '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 1.3.6
|
68
|
+
requirements: []
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 1.8.24
|
71
|
+
signing_key:
|
72
|
+
specification_version: 3
|
73
|
+
summary: after_false_destroy callback
|
74
|
+
test_files: []
|