Permalink
Browse files

Override _create and _destroy in order to also catch create! and dest…

…roy!.
  • Loading branch information...
1 parent 26ce22a commit 31682114f1f8c126077431325a3c00a3f8219c6d @postmodern committed Jul 17, 2010
Showing with 6 additions and 2 deletions.
  1. +6 −2 lib/dm-is-counter_cacheable/is/counter_cacheable.rb
@@ -53,13 +53,15 @@ def counter_cacheable(relationship_name,options={})
@counter_cache[relationship_name] = counter_property
end
+ private
+
#
# Creates a resource and increments the cache counters of the model.
#
# @return [DataMapper::Resource]
# The new resource.
#
- def create(*arguments)
+ def _create(*arguments)
resource = super(*arguments)
if self.counter_cache
@@ -77,13 +79,15 @@ def create(*arguments)
end
module InstanceMethods
+ private
+
#
# Destroys a resource and decrements the cache counters of the model.
#
# @return [Boolean]
# Specifies whether the resource was successfully destroyed.
#
- def destroy(*arguments)
+ def _destroy(*arguments)
if self.class.counter_cache
self.class.counter_cache.each do |relationship,property|
parent_resource = self.send(relationship)

0 comments on commit 3168211

Please sign in to comment.