rails-trash 1.1.2 → 2.0.0

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/rails-trash.rb +45 -41
  2. metadata +33 -7
@@ -2,76 +2,80 @@ module Rails
2
2
  module Trash
3
3
 
4
4
  def self.included(base)
5
- base.extend ClassMethods
5
+ base.send :extend, Extension
6
6
  end
7
7
 
8
- module ClassMethods
9
-
8
+ module Extension
10
9
  ##
11
10
  # class Entry < ActiveRecord::Base
12
11
  # has_trash
13
- # default_scope where(:deleted_at => nil)
14
12
  # end
15
13
  #
16
14
  def has_trash
17
- extend ClassMethodsMixin
15
+ extend ClassMethods
18
16
  include InstanceMethods
19
17
  alias_method_chain :destroy, :trash
20
18
  end
19
+ end
21
20
 
22
- module ClassMethodsMixin
23
-
24
- def deleted(field = nil, value = nil)
25
- deleted_at = Arel::Table.new(self.table_name)[:deleted_at]
26
- data = unscoped
27
- data = data.where(field => value) if field && value
28
- data.where(deleted_at.not_eq(nil))
29
- end
21
+ module ClassMethods
30
22
 
31
- def find_in_trash(id)
32
- deleted.find(id)
33
- end
23
+ def deleted(field = nil, value = nil)
24
+ deleted_at = Arel::Table.new(self.table_name)[:deleted_at]
25
+ data = unscoped
26
+ data = data.where(field => value) if field && value
27
+ data.where(deleted_at.not_eq(nil))
28
+ end
34
29
 
35
- def restore(id)
36
- find_in_trash(id).restore
37
- end
30
+ def find_in_trash(id)
31
+ deleted.find(id)
32
+ end
38
33
 
34
+ def restore(id)
35
+ find_in_trash(id).restore
39
36
  end
40
37
 
41
- module InstanceMethods
38
+ end
42
39
 
43
- def destroy_with_trash
44
- return destroy_without_trash if @trash_is_disabled
45
- deleted_at = Time.now.utc
46
- self.update_attribute(:deleted_at, deleted_at)
47
- self.class.reflect_on_all_associations(:has_many).each do |reflection|
48
- if reflection.options[:dependent].eql?(:destroy)
49
- self.send(reflection.name).update_all(:deleted_at => deleted_at)
50
- end
51
- end
52
- end
40
+ module InstanceMethods
53
41
 
54
- def restore
55
- self.update_attribute(:deleted_at, nil)
42
+ def self.included(base)
43
+ base.class_eval do
44
+ default_scope where(:deleted_at => nil) if arel_table[:deleted_at]
56
45
  end
46
+ end
57
47
 
58
- def disable_trash
59
- save_val = @trash_is_disabled
60
- begin
61
- @trash_is_disabled = true
62
- yield if block_given?
63
- ensure
64
- @trash_is_disabled = save_val
48
+ def destroy_with_trash
49
+ return destroy_without_trash if @trash_is_disabled
50
+ deleted_at = Time.now.utc
51
+ self.update_attribute(:deleted_at, deleted_at)
52
+ self.class.reflect_on_all_associations(:has_many).each do |reflection|
53
+ if reflection.options[:dependent].eql?(:destroy)
54
+ self.send(reflection.name).update_all(:deleted_at => deleted_at)
65
55
  end
66
56
  end
57
+ end
67
58
 
68
- def trashed?
69
- deleted_at.present?
59
+ def restore
60
+ self.update_attribute(:deleted_at, nil)
61
+ end
62
+
63
+ def disable_trash
64
+ save_val = @trash_is_disabled
65
+ begin
66
+ @trash_is_disabled = true
67
+ yield if block_given?
68
+ ensure
69
+ @trash_is_disabled = save_val
70
70
  end
71
+ end
71
72
 
73
+ def trashed?
74
+ deleted_at.present?
72
75
  end
73
76
 
74
77
  end
78
+
75
79
  end
76
80
  end
77
81
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-trash
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 2.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-07-15 00:00:00.000000000 +02:00
13
- default_executable:
12
+ date: 2011-09-11 00:00:00.000000000Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: rails
17
- requirement: &2153320580 !ruby/object:Gem::Requirement
16
+ requirement: &70170312315600 !ruby/object:Gem::Requirement
18
17
  none: false
19
18
  requirements:
20
19
  - - ! '>='
@@ -22,7 +21,29 @@ dependencies:
22
21
  version: 3.0.0
23
22
  type: :runtime
24
23
  prerelease: false
25
- version_requirements: *2153320580
24
+ version_requirements: *70170312315600
25
+ - !ruby/object:Gem::Dependency
26
+ name: factory_girl
27
+ requirement: &70170312314400 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 2.1.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70170312314400
36
+ - !ruby/object:Gem::Dependency
37
+ name: sqlite3
38
+ requirement: &70170312313380 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 1.3.4
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70170312313380
26
47
  description:
27
48
  email: contact@francescesplugas.com
28
49
  executables: []
@@ -30,7 +51,6 @@ extensions: []
30
51
  extra_rdoc_files: []
31
52
  files:
32
53
  - lib/rails-trash.rb
33
- has_rdoc: true
34
54
  homepage: https://github.com/fesplugas/rails-trash
35
55
  licenses: []
36
56
  post_install_message:
@@ -43,15 +63,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
43
63
  - - ! '>='
44
64
  - !ruby/object:Gem::Version
45
65
  version: '0'
66
+ segments:
67
+ - 0
68
+ hash: 4238735881725459162
46
69
  required_rubygems_version: !ruby/object:Gem::Requirement
47
70
  none: false
48
71
  requirements:
49
72
  - - ! '>='
50
73
  - !ruby/object:Gem::Version
51
74
  version: '0'
75
+ segments:
76
+ - 0
77
+ hash: 4238735881725459162
52
78
  requirements: []
53
79
  rubyforge_project:
54
- rubygems_version: 1.6.2
80
+ rubygems_version: 1.8.10
55
81
  signing_key:
56
82
  specification_version: 3
57
83
  summary: Trash