deactivatable 0.0.2 → 0.0.3
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.
- data/VERSION +1 -1
- data/lib/deactivatable.rb +13 -1
- data/test/deactivatable_test.rb +8 -0
- metadata +2 -2
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.0.
|
|
1
|
+
0.0.3
|
data/lib/deactivatable.rb
CHANGED
|
@@ -35,12 +35,20 @@ module ActiveRecord
|
|
|
35
35
|
# Yields to a block, executing that block after removing the deactivated_at scope.
|
|
36
36
|
#
|
|
37
37
|
def with_deactivated_objects_scope
|
|
38
|
-
|
|
38
|
+
remove_deactivated_objects_scope do
|
|
39
39
|
with_scope(:find => {:conditions => "`#{self.table_name}`.`deactivated_at` IS NOT NULL"}) do
|
|
40
40
|
yield
|
|
41
41
|
end
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
|
+
|
|
45
|
+
# Remove any scope related to deactivated_at and yield.
|
|
46
|
+
#
|
|
47
|
+
def remove_deactivated_objects_scope
|
|
48
|
+
with_exclusive_scope(scoped_methods_without_deactivated_at_scope) do
|
|
49
|
+
yield
|
|
50
|
+
end
|
|
51
|
+
end
|
|
44
52
|
|
|
45
53
|
private
|
|
46
54
|
# Scan the reflection associations defined on the current class,
|
|
@@ -58,6 +66,10 @@ module ActiveRecord
|
|
|
58
66
|
@deactivatable_options[:dependencies] << reflection_name
|
|
59
67
|
end
|
|
60
68
|
end
|
|
69
|
+
|
|
70
|
+
def scoped_methods_without_deactivated_at_scope
|
|
71
|
+
scoped_methods.reject {|m| m.values.map {|v| v.keys.first}.include?(:deactivated_at) }
|
|
72
|
+
end
|
|
61
73
|
|
|
62
74
|
end
|
|
63
75
|
|
data/test/deactivatable_test.rb
CHANGED
|
@@ -53,6 +53,10 @@ class DeactivatableTest < Test::Unit::TestCase
|
|
|
53
53
|
assert @inactive_item.deactivated?
|
|
54
54
|
end
|
|
55
55
|
|
|
56
|
+
should "be findable using the remove_deactivated_objects_scope" do
|
|
57
|
+
assert DeactivatableItem.remove_deactivated_objects_scope { DeactivatableItem.exists?(@inactive_item.id) }
|
|
58
|
+
end
|
|
59
|
+
|
|
56
60
|
context "when activated" do
|
|
57
61
|
setup do
|
|
58
62
|
@inactive_item.activate!
|
|
@@ -61,6 +65,10 @@ class DeactivatableTest < Test::Unit::TestCase
|
|
|
61
65
|
should "be findable" do
|
|
62
66
|
assert DeactivatableItem.exists?(@inactive_item.id)
|
|
63
67
|
end
|
|
68
|
+
|
|
69
|
+
should "be findable using the remove_deactivated_objects_scope" do
|
|
70
|
+
assert DeactivatableItem.remove_deactivated_objects_scope { DeactivatableItem.exists?(@inactive_item.id) }
|
|
71
|
+
end
|
|
64
72
|
end #when reactivated
|
|
65
73
|
end #An inactive item, @inactive_item
|
|
66
74
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: deactivatable
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Greg Fitzgerald
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2009-11-
|
|
12
|
+
date: 2009-11-12 00:00:00 -05:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|