acts_as_removable 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f55f6c4ecc0f0ced45e825af183aad144e21a974
4
- data.tar.gz: 4602fa5ebca4018257d7b799ea11cb23f4837a60
3
+ metadata.gz: d64a4e7fa07f7ffa3872fc9e3e39c86b1b6b1cc4
4
+ data.tar.gz: 37b0cad5a652328df6dc52fdd80879b16cca0253
5
5
  SHA512:
6
- metadata.gz: aecc89b6b88285c230e23a58db97b9c22f7291b9266f195fd93ece71cb2b68aa0cfb1e61798f532547acde46a9e9d11970c32443b844150c40d13203958030cf
7
- data.tar.gz: 57b8ea17f54ec4d3c37f354be41b666d68d0d73521ce92d78321e707a28e377acbe06b11801ba3536d3b4fdd9f0227caddf1daefedf31cdb2e40ec5d63af9021
6
+ metadata.gz: 3d73905579c97e93fe7f7743fb4304b7729116830b8f19af1ba793e87c1f5bc6aaa66cc0fff336ac1f2e3820efc01700b10b11b7fec49b68dedcf6996b226dd7
7
+ data.tar.gz: 23123253e8b3e88c184f47066b6d9948ced41868beeb5d4c8b2cfb72b5cdc5b454079818ab6ddb04c3d545ea2966560f2feaaa92d933b413af397cb708d9f19b
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 Florian Schwab
1
+ Copyright (c) 2013 SIC! Software GmbH
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -19,7 +19,7 @@ Or install it yourself as:
19
19
  ## Usage
20
20
 
21
21
  ```ruby
22
- # a column removed_at of type timestamp is required
22
+ # a column removed_at of type timestamp is required
23
23
  class MyModel < ActiveRecord::Base
24
24
  acts_as_removable
25
25
  end
@@ -37,6 +37,13 @@ class MyModel < ActiveRecord::Base
37
37
  end
38
38
  ```
39
39
 
40
+ It's possible to skip the default_scope:
41
+ ```ruby
42
+ class MyModel < ActiveRecord::Base
43
+ acts_as_removable without_default_scope: true
44
+ end
45
+ ```
46
+
40
47
  And you can use callbacks:
41
48
  ```ruby
42
49
  class MyModel < ActiveRecord::Base
@@ -50,6 +57,15 @@ class MyModel < ActiveRecord::Base
50
57
  def after_remove_method
51
58
  puts "After removing record"
52
59
  end
60
+
61
+ before_unremove do |r|
62
+ puts "Before unremoving record"
63
+ end
64
+
65
+ after_unremove :after_unremove_method
66
+ def after_unremove_method
67
+ puts "After unremoving record"
68
+ end
53
69
  end
54
70
  ```
55
71
 
@@ -57,6 +73,7 @@ end
57
73
 
58
74
  * [![Build Status](https://api.travis-ci.org/SICSoftwareGmbH/acts_as_removable.png)](https://travis-ci.org/SICSoftwareGmbH/acts_as_removable)
59
75
  * [![Dependencies](https://gemnasium.com/SICSoftwareGmbH/acts_as_removable.png?travis)](https://gemnasium.com/SICSoftwareGmbH/acts_as_removable)
76
+ * [![Code Climate](https://codeclimate.com/github/SICSoftwareGmbH/acts_as_removable.png)](https://codeclimate.com/github/SICSoftwareGmbH/acts_as_removable)
60
77
 
61
78
  ## Contributing
62
79
 
@@ -1,3 +1,3 @@
1
1
  module ActsAsRemovable
2
- VERSION = "0.9.1"
2
+ VERSION = "0.9.2"
3
3
  end
@@ -32,7 +32,7 @@ module ActsAsRemovable
32
32
  scope :actives, -> {unscoped.where("#{self.table_name}.#{self._acts_as_removable_column_name} IS NULL")}
33
33
  default_scope -> {actives} unless options[:without_default_scope]
34
34
 
35
- define_callbacks :remove
35
+ define_callbacks :remove, :unremove
36
36
 
37
37
  def self.before_remove(*args, &block)
38
38
  set_callback :remove, :before, *args, &block
@@ -42,30 +42,38 @@ module ActsAsRemovable
42
42
  set_callback :remove, :after, *args, &block
43
43
  end
44
44
 
45
+ def self.before_unremove(*args, &block)
46
+ set_callback :unremove, :before, *args, &block
47
+ end
48
+
49
+ def self.after_unremove(*args, &block)
50
+ set_callback :unremove, :after, *args, &block
51
+ end
52
+
45
53
  def removed?
46
54
  self.send(self.class._acts_as_removable_column_name).present?
47
55
  end
48
56
 
49
57
  def remove(options={})
50
- _update_remove_attribute(Time.now, false, options)
58
+ _update_remove_attribute(:remove, Time.now, false, options)
51
59
  end
52
60
 
53
61
  def remove!(options={})
54
- _update_remove_attribute(Time.now, true, options)
62
+ _update_remove_attribute(:remove, Time.now, true, options)
55
63
  end
56
64
 
57
65
  def unremove(options={})
58
- _update_remove_attribute(nil, false, options)
66
+ _update_remove_attribute(:unremove, nil, false, options)
59
67
  end
60
68
 
61
69
  def unremove!(options={})
62
- _update_remove_attribute(nil, true, options)
70
+ _update_remove_attribute(:unremove, nil, true, options)
63
71
  end
64
72
 
65
73
  private
66
74
 
67
- def _update_remove_attribute(value, with_bang=false, options={})
68
- run_callbacks :remove do
75
+ def _update_remove_attribute(callback, value, with_bang=false, options={})
76
+ run_callbacks callback.to_sym do
69
77
  self.send("#{self.class._acts_as_removable_column_name}=", value)
70
78
  with_bang ? self.save!(options) : self.save(options)
71
79
  end
@@ -3,12 +3,19 @@ require 'spec_helper'
3
3
  describe 'acts_as_removable' do
4
4
  class MyModel < ActiveRecord::Base
5
5
  acts_as_removable
6
- attr_accessor :callback_before, :callback_after
6
+ attr_accessor :callback_before_remove, :callback_after_remove, :callback_before_unremove, :callback_after_unremove
7
7
  before_remove do |r|
8
- r.callback_before = true
8
+ r.callback_before_remove = true
9
9
  end
10
10
  after_remove do |r|
11
- r.callback_after = true
11
+ r.callback_after_remove = true
12
+ end
13
+
14
+ before_unremove do |ur|
15
+ ur.callback_before_unremove = true
16
+ end
17
+ after_unremove do |ur|
18
+ ur.callback_after_unremove = true
12
19
  end
13
20
  end
14
21
 
@@ -68,10 +75,24 @@ describe 'acts_as_removable' do
68
75
 
69
76
  it "test callbacks" do
70
77
  r = MyModel.create!
71
- r.callback_before.should be_false
72
- r.callback_after.should be_false
78
+ r.callback_before_remove.should be_false
79
+ r.callback_after_remove.should be_false
80
+ r.callback_before_unremove.should be_false
81
+ r.callback_after_unremove.should be_false
82
+
73
83
  r.remove
74
- r.callback_before.should be_true
75
- r.callback_after.should be_true
84
+
85
+ r.callback_before_remove.should be_true
86
+ r.callback_after_remove.should be_true
87
+ r.callback_before_unremove.should be_false
88
+ r.callback_after_unremove.should be_false
89
+
90
+ r.unremove
91
+
92
+ r.callback_before_remove.should be_true
93
+ r.callback_after_remove.should be_true
94
+ r.callback_before_unremove.should be_true
95
+ r.callback_after_unremove.should be_true
96
+
76
97
  end
77
98
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_removable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Schwab
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-25 00:00:00.000000000 Z
11
+ date: 2013-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport