sequel-paranoid 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/sequel/plugins/paranoid.rb +53 -0
  2. metadata +66 -0
@@ -0,0 +1,53 @@
1
+ require 'sequel'
2
+
3
+ module Sequel::Plugins
4
+ module Paranoid
5
+ def self.configure(model, options = {})
6
+ model.instance_eval do
7
+
8
+ #
9
+ # Inject the scopes for the deleted and the existing entries.
10
+ #
11
+
12
+ dataset_module do
13
+ def deleted
14
+ unfiltered.exclude(:deleted_at => nil)
15
+ end
16
+
17
+ def existing
18
+ unfiltered.filter(:deleted_at => nil)
19
+ end
20
+ end
21
+
22
+ #
23
+ # Shortcut method to return the unfiltered dataset.
24
+ #
25
+
26
+ def unfiltered
27
+ dataset.unfiltered
28
+ end
29
+
30
+ #
31
+ # Overwrite the "destroy" method.
32
+ #
33
+
34
+ define_method("destroy") do
35
+ self.before_destroy if self.respond_to?(:before_destroy)
36
+
37
+ self.deleted_at = Time.now
38
+
39
+ if save and self.respond_to?(:after_destroy)
40
+ self.after_destroy
41
+ end
42
+ end
43
+
44
+
45
+ #
46
+ # Inject the default scope that filters deleted entries.
47
+ #
48
+
49
+ set_dataset(self.existing)
50
+ end
51
+ end
52
+ end
53
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sequel-paranoid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Sascha Depold
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sequel
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
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: Use this plugin to mark a model instance as deleted without loosing its
31
+ actual data.
32
+ email: sascha@depold.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - lib/sequel/plugins/paranoid.rb
38
+ homepage: https://github.com/sdepold/sequel-paranoid
39
+ licenses:
40
+ - MIT
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ segments:
52
+ - 0
53
+ hash: 3660781128148827115
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project:
62
+ rubygems_version: 1.8.23
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: A plugin for the Ruby ORM Sequel, that allows soft deletion of database entries.
66
+ test_files: []