soft_delete-rails 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 John Cant
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,25 @@
1
+ soft _ delete
2
+ ===========
3
+
4
+ Add a column
5
+ ```
6
+ deleted_at
7
+ ```
8
+ to your model
9
+
10
+ Make a model soft deletable by calling
11
+ ```
12
+ soft_deletable
13
+ ```
14
+ in your class definition
15
+
16
+
17
+ Doesn't mess with your queries or anything like that.
18
+
19
+ Example
20
+ =======
21
+
22
+ Example goes here. TODO
23
+
24
+
25
+ Copyright (c) 2012 John Cant, released under the MIT license
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env rake
2
+ require 'rake/testtask'
3
+ require 'rdoc/task'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the soft_delete plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.libs << 'test'
12
+ t.pattern = 'test/**/*_test.rb'
13
+ t.verbose = true
14
+ end
15
+
16
+ desc 'Generate documentation for the soft_delete plugin.'
17
+ RDoc::Task.new(:rdoc) do |rdoc|
18
+ rdoc.rdoc_dir = 'rdoc'
19
+ rdoc.title = 'SoftDelete'
20
+ rdoc.options << '--line-numbers' << '--inline-source'
21
+ rdoc.rdoc_files.include('README')
22
+ rdoc.rdoc_files.include('lib/**/*.rb')
23
+ end
@@ -0,0 +1 @@
1
+ # Install hook code here
@@ -0,0 +1,72 @@
1
+ module SoftDeletable
2
+
3
+ module InstanceMethods
4
+
5
+ def self.included(base)
6
+ base.class_eval do
7
+ alias_method :hard_delete, :delete
8
+ alias_method :delete, :soft_delete
9
+ alias_method :hard_destroy, :destroy
10
+ alias_method :destroy, :soft_destroy
11
+ end
12
+ end
13
+
14
+ def soft_delete
15
+ update_column :deleted_at, Time.now
16
+ end
17
+
18
+ def soft_destroy
19
+ _run_destroy_callbacks do
20
+ destroy_associations
21
+ delete
22
+ end
23
+ end
24
+
25
+
26
+ # default_scope where()
27
+
28
+ # def self.included(base)
29
+ # base.reflect_on_all_associations.each do |a|
30
+ # if a.collection
31
+ # a.class_name.constantize.send :define_method, do
32
+ # end
33
+ # end
34
+ end
35
+
36
+
37
+ module Base
38
+ def self.included(base)
39
+ base.extend ClassMethods
40
+ end
41
+
42
+ module ClassMethods
43
+
44
+ def soft_deletable
45
+ include SoftDeletable::InstanceMethods
46
+ scope :not_deleted, where(:deleted_at => nil)
47
+ scope :deleted, where("#{self.to_s.underscore.pluralize.to_sym}.deleted_at IS NOT NULL")
48
+ end
49
+
50
+ end
51
+ end
52
+
53
+ module TestCase
54
+
55
+ def assert_soft_deleted(record, msg=nil)
56
+ full_message = build_message(msg, "? has not been soft deleted", record.inspect)
57
+ assert_block(full_message) do
58
+ record.deleted_at != nil
59
+ end
60
+ end
61
+
62
+ def assert_not_soft_deleted(record, msg=nil)
63
+ full_message = build_message(msg, "? was soft deleted at", record.inspect, record.deleted_at)
64
+ assert_block(full_message) do
65
+ record.deleted_at == nil
66
+ end
67
+ end
68
+
69
+ end
70
+ end
71
+
72
+
@@ -0,0 +1,2 @@
1
+ require File.expand_path("../soft_deletable", __FILE__)
2
+ require File.expand_path("../soft_delete/rails", __FILE__)
@@ -0,0 +1,8 @@
1
+ module SoftDelete
2
+ class Railtie < Rails::Railtie
3
+ initializer "soft_delete.configure_rails_initialization" do
4
+ ::ActiveRecord::Base.send(:include, ::SoftDeletable::Base)
5
+ ::ActiveSupport::TestCase.send(:include, ::SoftDeletable::TestCase)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module SoftDelete
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,12 @@
1
+ #$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
2
+ require File.expand_path("../lib/soft_delete/version", __FILE__)
3
+
4
+ Gem::Specification.new "soft_delete-rails", SoftDelete::VERSION do |s|
5
+ s.summary = "Simple and unobtrusive soft delete for rails"
6
+ s.authors = ["John Cant"]
7
+ s.email = "a.johncant@gmail.com"
8
+ s.homepage = "http://github.com/johncant/soft_delete-rails"
9
+ s.files = `git ls-files`.split("\n")
10
+ s.license = 'MIT'
11
+ s.require_path = 'lib'
12
+ end
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: soft_delete-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - John Cant
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-21 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description:
15
+ email: a.johncant@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - MIT-LICENSE
21
+ - README.md
22
+ - Rakefile
23
+ - install.rb
24
+ - lib/soft_deletable.rb
25
+ - lib/soft_delete-rails.rb
26
+ - lib/soft_delete/rails.rb
27
+ - lib/soft_delete/version.rb
28
+ - soft_delete-rails.gemspec
29
+ - uninstall.rb
30
+ homepage: http://github.com/johncant/soft_delete-rails
31
+ licenses:
32
+ - MIT
33
+ post_install_message:
34
+ rdoc_options: []
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubyforge_project:
51
+ rubygems_version: 1.8.15
52
+ signing_key:
53
+ specification_version: 3
54
+ summary: Simple and unobtrusive soft delete for rails
55
+ test_files: []