jchupp-is_paranoid 0.4.0 → 0.5.0
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/README.textile +0 -1
- data/VERSION.yml +2 -2
- data/lib/is_paranoid.rb +16 -25
- metadata +2 -2
data/README.textile
CHANGED
@@ -94,7 +94,6 @@ h3. and you may ask yourself, where does that highway go to?
|
|
94
94
|
If you find any bugs, have any ideas of features you think are missing, or find things you're like to see work differently, feel free to send me a message or a pull request.
|
95
95
|
|
96
96
|
Currently on the todo list:
|
97
|
-
* deal with validates_uniqueness_of issue
|
98
97
|
* add options for merging additional default_scope options (i.e. order, etc.)
|
99
98
|
|
100
99
|
h3. Thanks
|
data/VERSION.yml
CHANGED
data/lib/is_paranoid.rb
CHANGED
@@ -1,32 +1,23 @@
|
|
1
1
|
require 'activerecord'
|
2
2
|
|
3
3
|
module IsParanoid
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
#
|
17
|
-
# If you want to include ActiveRecord::Calculations to include your
|
18
|
-
# destroyed models, do is_paranoid :with_calculations => true and you
|
19
|
-
# will get sum_with_deleted, count_with_deleted, etc.
|
20
|
-
def is_paranoid opts = {}
|
21
|
-
opts[:field] ||= [:deleted_at, Proc.new{Time.now.utc}, nil]
|
22
|
-
class_inheritable_accessor :destroyed_field, :field_destroyed, :field_not_destroyed
|
23
|
-
self.destroyed_field, self.field_destroyed, self.field_not_destroyed = opts[:field]
|
4
|
+
# Call this in your model to enable all the safety-net goodness
|
5
|
+
#
|
6
|
+
# Example:
|
7
|
+
#
|
8
|
+
# class Android < ActiveRecord::Base
|
9
|
+
# is_paranoid
|
10
|
+
# end
|
11
|
+
#
|
12
|
+
def is_paranoid opts = {}
|
13
|
+
opts[:field] ||= [:deleted_at, Proc.new{Time.now.utc}, nil]
|
14
|
+
class_inheritable_accessor :destroyed_field, :field_destroyed, :field_not_destroyed
|
15
|
+
self.destroyed_field, self.field_destroyed, self.field_not_destroyed = opts[:field]
|
24
16
|
|
25
|
-
|
26
|
-
end
|
17
|
+
include ClassAndInstanceMethods
|
27
18
|
end
|
28
19
|
|
29
|
-
module
|
20
|
+
module ClassAndInstanceMethods
|
30
21
|
def self.included(base)
|
31
22
|
base.class_eval do
|
32
23
|
# This is the real magic. All calls made to this model will append
|
@@ -86,7 +77,7 @@ module IsParanoid
|
|
86
77
|
# end
|
87
78
|
define_method name do |*args|
|
88
79
|
self.with_exclusive_scope do
|
89
|
-
with_scope({:find => { :conditions => ["#{destroyed_field} IS NOT ?", field_not_destroyed] }}) do
|
80
|
+
with_scope({:find => { :conditions => ["#{self.table_name}.#{destroyed_field} IS NOT ?", field_not_destroyed] }}) do
|
90
81
|
self.send($1, *args)
|
91
82
|
end
|
92
83
|
end
|
@@ -103,4 +94,4 @@ module IsParanoid
|
|
103
94
|
end
|
104
95
|
end
|
105
96
|
|
106
|
-
ActiveRecord::Base.send(:
|
97
|
+
ActiveRecord::Base.send(:extend, IsParanoid)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jchupp-is_paranoid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeffrey Chupp
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-04-12 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|