public
Description: ActiveRecord plugin allowing you to hide and restore records without actually deleting them.
Clone URL: git://github.com/technoweenie/acts_as_paranoid.git
rule number one is you do not override base classes

git-svn-id: 
http://svn.techno-weenie.net/projects/plugins/acts_as_paranoid@488 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Tue Dec 20 19:54:17 -0800 2005
commit  740a62d0974afa7e9d4e7a608fb3f7bae56cfda1
tree    a1ce3ba2ba38ae11f32b35af8d4086cc86cd95a3
parent  11a658a58a6c71b65705811d80613e7eb27c48ec
...
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
 
272
...
159
160
161
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
163
164
165
 
 
 
 
 
 
166
167
168
0
@@ -159,112 +159,8 @@ module Caboose #:nodoc:
0
           end
0
         end
0
       end
0
-
0
- module AssociationProxy #:nodoc:
0
- protected
0
- def find_with_deleted?
0
- @owner.class.paranoid? and @owner.deleted_at
0
- end
0
-
0
- def options_with_deleted!(options)
0
- options[:with_deleted] = find_with_deleted? if @association_class.paranoid?
0
- options
0
- end
0
- end
0
-
0
- module BelongsToAssociation #:nodoc:
0
- def self.included(base)
0
- base.send :alias_method, :find_target_without_deleted, :find_target
0
- base.send :alias_method, :find_target, :find_target_with_deleted
0
- end
0
-
0
- private
0
- def find_target_with_deleted
0
- options = { :include => @options[:include] }
0
- options[:conditions] = interpolate_sql(@options[:conditions]) if @options[:conditions]
0
- options_with_deleted! options
0
-
0
- @association_class.find(@owner[@association_class_primary_key_name], options)
0
- end
0
- end
0
-
0
- module HasOneAssociation #:nodoc:
0
- def self.included(base)
0
- base.send :alias_method, :find_target_without_deleted, :find_target
0
- base.send :alias_method, :find_target, :find_target_with_deleted
0
- end
0
-
0
- private
0
- def find_target_with_deleted
0
- @association_class.find :first, options_with_deleted!(:conditions => @finder_sql,
0
- :order => @options[:order],
0
- :include => @options[:include])
0
- end
0
- end
0
-
0
- module HasManyAssociation #:nodoc:
0
- def self.included(base)
0
- base.send :alias_method, :find_target_without_deleted, :find_target
0
- base.send :alias_method, :find_target, :find_target_with_deleted
0
- base.send :alias_method, :count_records_without_deleted, :count_records
0
- base.send :alias_method, :count_records, :count_records_with_deleted
0
- end
0
-
0
- private
0
- def find_target_with_deleted
0
- if @options[:finder_sql]
0
- @association_class.find_by_sql(@finder_sql)
0
- else
0
- @association_class.find(:all,
0
- options_with_deleted!(:conditions => @finder_sql,
0
- :order => @options[:order],
0
- :limit => @options[:limit],
0
- :joins => @options[:joins],
0
- :include => @options[:include],
0
- :group => @options[:group])
0
- )
0
- end
0
- end
0
-
0
- def count_records_with_deleted
0
- count = if has_cached_counter?
0
- @owner.send(:read_attribute, cached_counter_attribute_name)
0
- elsif @options and @options[:counter_sql]
0
- @association_class.count_by_sql(@counter_sql)
0
- else
0
- @association_class.send((find_with_deleted? ? :count_with_deleted : :count), @counter_sql)
0
- end
0
-
0
- @target = [] and loaded if count == 0
0
-
0
- return count
0
- end
0
- end
0
-
0
- module HasAndBelongsToManyAssociation #:nodoc:
0
- def self.included(base)
0
- base.send :alias_method, :find_target_without_deleted, :find_target
0
- base.send :alias_method, :find_target, :find_target_with_deleted
0
- end
0
-
0
- private
0
- def find_target_with_deleted
0
- if @options and @options[:finder_sql]
0
- records = @association_class.find_by_sql(@finder_sql)
0
- else
0
- records = find(:all, options_with_deleted!(:include => @options[:include]))
0
- end
0
-
0
- @options[:uniq] ? uniq(records) : records
0
- end
0
- end
0
     end
0
   end
0
 end
0
 
0
-ActiveRecord::Base.send :include, Caboose::Acts::Paranoid::ActiveRecord
0
-ActiveRecord::Associations::AssociationProxy.send :include, Caboose::Acts::Paranoid::AssociationProxy
0
-ActiveRecord::Associations::BelongsToAssociation.send :include, Caboose::Acts::Paranoid::BelongsToAssociation
0
-ActiveRecord::Associations::HasOneAssociation.send :include, Caboose::Acts::Paranoid::HasOneAssociation
0
-ActiveRecord::Associations::HasManyAssociation.send :include, Caboose::Acts::Paranoid::HasManyAssociation
0
-ActiveRecord::Associations::HasAndBelongsToManyAssociation.send :include, Caboose::Acts::Paranoid::HasAndBelongsToManyAssociation
0
\ No newline at end of file
0
+ActiveRecord::Base.send :include, Caboose::Acts::Paranoid::ActiveRecord
0
\ No newline at end of file
...
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
145
146
...
118
119
120
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
0
@@ -118,29 +118,30 @@ class ParanoidTest < Test::Unit::TestCase
0
     assert !NonParanoidAndroid.paranoid?
0
   end
0
 
0
- def test_should_find_deleted_has_many_assocations_on_deleted_records_by_default
0
- w = Widget.find_with_deleted 2
0
- assert_equal 2, w.categories.length
0
- assert_equal 2, w.categories(true).size
0
- end
0
-
0
- def test_should_find_deleted_habtm_assocations_on_deleted_records_by_default
0
- w = Widget.find_with_deleted 2
0
- assert_equal 2, w.habtm_categories.length
0
- assert_equal 2, w.habtm_categories(true).size
0
- end
0
-
0
- def test_should_find_deleted_has_one_associations_on_deleted_records_by_default
0
- c = Category.find_with_deleted 3
0
- w = Widget.find_with_deleted 2
0
- assert_equal c, w.category
0
- end
0
-
0
- def test_should_find_deleted_belongs_to_associations_on_deleted_records_by_default
0
- c = Category.find_with_deleted 3
0
- w = Widget.find_with_deleted 2
0
- assert_equal c, w.parent_category
0
- end
0
+ # sorry charlie, these are out!
0
+ #def test_should_find_deleted_has_many_assocations_on_deleted_records_by_default
0
+ # w = Widget.find_with_deleted 2
0
+ # assert_equal 2, w.categories.length
0
+ # assert_equal 2, w.categories(true).size
0
+ #end
0
+ #
0
+ #def test_should_find_deleted_habtm_assocations_on_deleted_records_by_default
0
+ # w = Widget.find_with_deleted 2
0
+ # assert_equal 2, w.habtm_categories.length
0
+ # assert_equal 2, w.habtm_categories(true).size
0
+ #end
0
+ #
0
+ #def test_should_find_deleted_has_one_associations_on_deleted_records_by_default
0
+ # c = Category.find_with_deleted 3
0
+ # w = Widget.find_with_deleted 2
0
+ # assert_equal c, w.category
0
+ #end
0
+ #
0
+ #def test_should_find_deleted_belongs_to_associations_on_deleted_records_by_default
0
+ # c = Category.find_with_deleted 3
0
+ # w = Widget.find_with_deleted 2
0
+ # assert_equal c, w.parent_category
0
+ #end
0
 end
0
 
0
 class Array

Comments

    No one has commented yet.