trashcan 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NDcyMDlmZjQ1YzdkNWMxYWEyNTdjYjUwNTUyNWZiODBiODY0ZmY1OA==
5
+ data.tar.gz: !binary |-
6
+ M2U3MWE2ZDBjZDM5ODQ3NTcxMDUxZDU3MTYwMWVjOWU1MzFjMDA0Yw==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ ZDUyYzM5ZGM2ZWI5MzJhMzY2ODUxZTkyOGRhZWU5NmJhNGUzZTk4M2UwNjgy
10
+ NGVhODBmMzU0YTRmNGJjODAyMDkwOWNlMjhhMDlmOWQwYjc4MTEyOWNjMWMz
11
+ N2UxNDllNDBmNTFmMmQ0MDc2ZmNhMWY0MDM4OWE5OTFlMzk2Mjc=
12
+ data.tar.gz: !binary |-
13
+ OWMwY2M4ODIxMWMzZDFlNjcwMGM5ZTFmN2FmNDExOTA2OWFiYjI5MjE0ZmRj
14
+ ZGEyMWM3ZThjYTg4ZTJiNDI1NThjMWViYWYxZWI4OWJjMTY0YWZhOGMyZDg3
15
+ NGZhM2ZjYjFkZDhjYTQ2ZjY4OTA2ZjZhYzQ5NjIxZTQ3YjY0MGI=
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .project
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in trashcan.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Andy
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Trashcan
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'trashcan'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install trashcan
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,4 @@
1
+ require "trashcan/version"
2
+ require 'trashcan/active_record_ext'
3
+
4
+ ActiveRecord::Base.__send__(:extend, Trashcan::ActiveRecordExt::ClassMethods)
@@ -0,0 +1,52 @@
1
+ module Trashcan
2
+ module ActiveRecordExt
3
+ module ClassMethods
4
+
5
+ def trashable(options = {})
6
+ field = options[:field] || :trashed
7
+ field = field.to_sym if field.is_a? String
8
+
9
+ singleton_class.send :define_method, :trashable_field_name do
10
+ field
11
+ end
12
+
13
+ send :scope, "#{trashable_field_name}", where("#{trashable_field_name} = ?", true)
14
+ send :scope, "not_#{trashable_field_name}", where("#{trashable_field_name} = ?", false)
15
+
16
+ raise "No such field #{trashable_field_name} in the #{table_name} table" unless ActiveRecord::Base.connection.column_exists?(table_name, trashable_field_name)
17
+
18
+ alias_method :force_destroy, :destroy
19
+
20
+ define_method "#{trashable_field_name}?" do
21
+ send(field)
22
+ end
23
+
24
+ define_method :destroy do |*args|
25
+ opts = args.pop || {}
26
+
27
+ force = opts[:force]
28
+ should_force = force.respond_to?(:call) ? force.call : force
29
+
30
+ if should_force
31
+ force_destroy
32
+ else
33
+ update_attribute(field, true)
34
+ end
35
+ end
36
+
37
+ define_method :restore do
38
+ update_attribute(field, false)
39
+ end
40
+
41
+ define_method :set_trashable_field_false do
42
+ if new_record? and send(field).nil?
43
+ send("#{field}=", false)
44
+ end
45
+ end
46
+
47
+ after_initialize :set_trashable_field_false
48
+
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,3 @@
1
+ module Trashcan
2
+ VERSION = "0.0.4"
3
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'trashcan/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "trashcan"
8
+ gem.version = Trashcan::VERSION
9
+ gem.authors = ["Andy"]
10
+ gem.email = ["andreas@robecke.de"]
11
+ gem.description = %q{Soft delete active record models}
12
+ gem.summary = %q{Overwrites the active record destroy method}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trashcan
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Andy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-04-07 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Soft delete active record models
14
+ email:
15
+ - andreas@robecke.de
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - .gitignore
21
+ - Gemfile
22
+ - LICENSE.txt
23
+ - README.md
24
+ - Rakefile
25
+ - lib/trashcan.rb
26
+ - lib/trashcan/active_record_ext.rb
27
+ - lib/trashcan/version.rb
28
+ - trashcan.gemspec
29
+ homepage: ''
30
+ licenses: []
31
+ metadata: {}
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubyforge_project:
48
+ rubygems_version: 2.0.3
49
+ signing_key:
50
+ specification_version: 4
51
+ summary: Overwrites the active record destroy method
52
+ test_files: []