Module: Cms::Behaviors::SoftDeleting::ClassMethods
- Defined in:
- lib/cms/behaviors/soft_deleting.rb
Overview
TODO: Refactor this class to remove need for overriding count, delete_all, etc. Should not be necessary due to introduction of ‘default_scope’.
-
TODO: Allow a record to define its own default_scope that doesn’t ‘override’ this one.
See github.com/fernandoluizao/acts_as_active for an implementation of this
Instance Method Summary collapse
-
#count_with_deleted(*args) ⇒ Object
Returns a count of all records of this type, including those marked as deleted.
- #delete_all(conditions = nil) ⇒ Object
- #exists?(id_or_conditions) ⇒ Boolean
-
#find_with_deleted(*args) ⇒ Object
Returns all records, including those which are marked as deleted.
Instance Method Details
#count_with_deleted(*args) ⇒ Object
Returns a count of all records of this type, including those marked as deleted.
Behaves like ActiveRecord.count is originally implemented.
60 61 62 |
# File 'lib/cms/behaviors/soft_deleting.rb', line 60 def count_with_deleted(* args) self.with_exclusive_scope { count(* args) } end |
#delete_all(conditions = nil) ⇒ Object
64 65 66 |
# File 'lib/cms/behaviors/soft_deleting.rb', line 64 def delete_all(conditions=nil) update_all(["deleted = ?", true], conditions) end |
#exists?(id_or_conditions) ⇒ Boolean
68 69 70 71 72 73 74 75 |
# File 'lib/cms/behaviors/soft_deleting.rb', line 68 def exists?(id_or_conditions) if id_or_conditions.is_a?(Hash) || id_or_conditions.is_a?(Array) conditions = {:conditions => id_or_conditions} else conditions = {:conditions => {:id => id_or_conditions}} end count(conditions) > 0 end |
#find_with_deleted(*args) ⇒ Object
Returns all records, including those which are marked as deleted.
Basically ‘find’ exactly how ActiveRecord originally implements it.
51 52 53 |
# File 'lib/cms/behaviors/soft_deleting.rb', line 51 def find_with_deleted(* args) self.with_exclusive_scope { find(* args) } end |