mark_as_deleted 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 +3 -0
- data/Rakefile +8 -0
- data/lib/mark_as_deleted.rb +5 -0
- data/lib/mark_as_deleted/active_record.rb +13 -0
- data/lib/mark_as_deleted/version.rb +3 -0
- data/mark_as_deleted.gemspec +23 -0
- data/spec/mark_as_deleted/active_record_spec.rb +37 -0
- data/spec/spec_helper.rb +1 -0
- metadata +96 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
module MarkAsDeleted
|
2
|
+
module ActiveRecord
|
3
|
+
def mark_as_deleted(deleted_column = :deleted)
|
4
|
+
define_method(:destroy) do
|
5
|
+
self.update_attributes(deleted_column => true)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
if defined?(::ActiveRecord)
|
12
|
+
ActiveRecord::Base.extend MarkAsDeleted::ActiveRecord
|
13
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'mark_as_deleted/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'mark_as_deleted'
|
7
|
+
s.version = MarkAsDeleted::VERSION
|
8
|
+
s.authors = ['Vsevolod Romashov']
|
9
|
+
s.email = ['7@7vn.ru']
|
10
|
+
s.homepage = "https://github.com/7even/mark_as_deleted"
|
11
|
+
s.summary = "Allows to mark AR objects as deleted instead of actual deletion"
|
12
|
+
s.description = "A simple gem that adds mark_as_deleted ActiveRecord macro. Models having this are not actually being deleted, they are marked as deleted instead."
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ['lib']
|
18
|
+
|
19
|
+
s.add_dependency 'activerecord', '~> 3'
|
20
|
+
|
21
|
+
s.add_development_dependency 'rake'
|
22
|
+
s.add_development_dependency 'rspec'
|
23
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class Person
|
4
|
+
extend MarkAsDeleted::ActiveRecord
|
5
|
+
end
|
6
|
+
|
7
|
+
describe MarkAsDeleted::ActiveRecord do
|
8
|
+
describe ".mark_as_deleted" do
|
9
|
+
context "without a parameter" do
|
10
|
+
before(:each) do
|
11
|
+
class Person
|
12
|
+
mark_as_deleted
|
13
|
+
end
|
14
|
+
@person = Person.new
|
15
|
+
end
|
16
|
+
|
17
|
+
it "(re)defines a #destroy method that updates :deleted column to true" do
|
18
|
+
@person.should_receive(:update_attributes).with(:deleted => true)
|
19
|
+
@person.destroy
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "with a parameter" do
|
24
|
+
before(:each) do
|
25
|
+
class Person
|
26
|
+
mark_as_deleted :is_deleted
|
27
|
+
end
|
28
|
+
@person = Person.new
|
29
|
+
end
|
30
|
+
|
31
|
+
it "(re)defines a #destroy method that updates mark_as_deleted parameter column to true" do
|
32
|
+
@person.should_receive(:update_attributes).with(:is_deleted => true)
|
33
|
+
@person.destroy
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'mark_as_deleted'
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mark_as_deleted
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Vsevolod Romashov
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-12-23 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activerecord
|
16
|
+
requirement: &70322130288780 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70322130288780
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rake
|
27
|
+
requirement: &70322130274460 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70322130274460
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
requirement: &70322130273740 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70322130273740
|
47
|
+
description: A simple gem that adds mark_as_deleted ActiveRecord macro. Models having
|
48
|
+
this are not actually being deleted, they are marked as deleted instead.
|
49
|
+
email:
|
50
|
+
- 7@7vn.ru
|
51
|
+
executables: []
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- .gitignore
|
56
|
+
- Gemfile
|
57
|
+
- Rakefile
|
58
|
+
- lib/mark_as_deleted.rb
|
59
|
+
- lib/mark_as_deleted/active_record.rb
|
60
|
+
- lib/mark_as_deleted/version.rb
|
61
|
+
- mark_as_deleted.gemspec
|
62
|
+
- spec/mark_as_deleted/active_record_spec.rb
|
63
|
+
- spec/spec_helper.rb
|
64
|
+
homepage: https://github.com/7even/mark_as_deleted
|
65
|
+
licenses: []
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
segments:
|
77
|
+
- 0
|
78
|
+
hash: 2182875662807839825
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
hash: 2182875662807839825
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 1.8.10
|
91
|
+
signing_key:
|
92
|
+
specification_version: 3
|
93
|
+
summary: Allows to mark AR objects as deleted instead of actual deletion
|
94
|
+
test_files:
|
95
|
+
- spec/mark_as_deleted/active_record_spec.rb
|
96
|
+
- spec/spec_helper.rb
|