Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow :with_deleted and :only_deleted options to work with count and …

…calculate. Fixes compatibility with will_paginate.
  • Loading branch information...
commit b0a5d2b8ba89eae03f673e4af2e52619260fcc30 1 parent e90a16f
James Le Cuirot chewi authored
Showing with 23 additions and 6 deletions.
  1. +5 −0 CHANGELOG
  2. +18 −6 lib/caboose/acts/paranoid.rb
5 CHANGELOG
View
@@ -1,3 +1,8 @@
+* (16 Apr 2009)
+
+Allow :with_deleted and :only_deleted options to work with count and calculate.
+Fixes compatibility with will_paginate. [James Le Cuirot]
+
* (4 Oct 2007)
Update for Edge rails: remove support for legacy #count args
24 lib/caboose/acts/paranoid.rb
View
@@ -120,11 +120,19 @@ def count_only_deleted(*args)
end
def count(*args)
- with_deleted_scope { count_with_deleted(*args) }
+ with, only = extract_deleted_options(args.last) if args.last.is_a?(Hash)
+
+ with ? count_with_deleted(*args) :
+ only ? count_only_deleted(*args) :
+ with_deleted_scope { count_with_deleted(*args) }
end
def calculate(*args)
- with_deleted_scope { calculate_with_deleted(*args) }
+ with, only = extract_deleted_options(args.last) if args.last.is_a?(Hash)
+
+ with ? calculate_with_deleted(*args) :
+ only ? calculate_only_deleted(*args) :
+ with_deleted_scope { calculate_with_deleted(*args) }
end
def delete_all(conditions = nil)
@@ -147,12 +155,16 @@ def with_only_deleted_scope(&block)
private
# all find calls lead here
def find_every(options)
- options.delete(:with_deleted) ?
- find_every_with_deleted(options) :
- options.delete(:only_deleted) ?
- with_only_deleted_scope { find_every_with_deleted(options) } :
+ with, only = extract_deleted_options(options)
+
+ with ? find_every_with_deleted(options) :
+ only ? with_only_deleted_scope { find_every_with_deleted(options) } :
with_deleted_scope { find_every_with_deleted(options) }
end
+
+ def extract_deleted_options(options)
+ return options.delete(:with_deleted), options.delete(:only_deleted)
+ end
end
def destroy_without_callbacks
Please sign in to comment.
Something went wrong with that request. Please try again.