Permalink
Browse files

Don't use InstanceMethods since ActiveSupport::Concern deprecated it.

  • Loading branch information...
1 parent 0775f51 commit c3dcfcc8426001623571af321ccc0a5f61a27bed @jpr5 jpr5 committed Aug 25, 2012
Showing with 35 additions and 40 deletions.
  1. +35 −40 lib/mongo/locking/model_methods.rb
@@ -57,49 +57,44 @@ def locker
end # ClassMethods
- module InstanceMethods
-
- # Main closure-based lock method. opts remains present for
- # future utility.
- def lock(opts = {})
- raise ArgumentError, "#{self.class.name}#lock requires a block" unless block_given?
-
- # Look for the top level lockable
- lockable = self.class.locker.root_for(self)
-
- # Try to acquire the lock. If succeeds, "locked" will be set
- locked = lockable.class.locker.acquire(lockable)
-
- return yield
-
- rescue Mongo::Locking::Exceptions::Error => e
- Locking.error "#{self.class.name}#lock failed"
- raise e
-
- ensure
- # Only unlock if "locked" was set. We're using this to
- # distinguish between an exception from the yield vs. an
- # exception from our own locking code. Doing it in an
- # ensure block makes us defensible against a return from
- # within the closure, too.
- #
- # Calling lockable's locker instead of self potentially
- # saves us the cost of "find root lockable" that locker
- # would perform.
- lockable.class.locker.release(lockable) if locked
- end
+ # Main closure-based lock method. opts remains present for
+ # future utility.
+ def lock(opts = {})
+ raise ArgumentError, "#{self.class.name}#lock requires a block" unless block_given?
- # Return true if operating within an open acquired lock.
- def have_lock?
- lockable = self.class.locker.root_for(self)
- locker = lockable.class.locker
- key = locker.key_for(lockable)
- return locker.refcounts[key] > 0
- end
+ # Look for the top level lockable
+ lockable = self.class.locker.root_for(self)
+
+ # Try to acquire the lock. If succeeds, "locked" will be set
+ locked = lockable.class.locker.acquire(lockable)
+
+ return yield
- end # InstanceMethods
+ rescue Mongo::Locking::Exceptions::Error => e
+ Locking.error "#{self.class.name}#lock failed"
+ raise e
+
+ ensure
+ # Only unlock if "locked" was set. We're using this to
+ # distinguish between an exception from the yield vs. an
+ # exception from our own locking code. Doing it in an
+ # ensure block makes us defensible against a return from
+ # within the closure, too.
+ #
+ # Calling lockable's locker instead of self potentially
+ # saves us the cost of "find root lockable" that locker
+ # would perform.
+ lockable.class.locker.release(lockable) if locked
+ end
+
+ # Return true if operating within an open acquired lock.
+ def have_lock?
+ lockable = self.class.locker.root_for(self)
+ locker = lockable.class.locker
+ key = locker.key_for(lockable)
+ return locker.refcounts[key] > 0
+ end
end # ModelMethods
end # Locking
end # Mongo
-

0 comments on commit c3dcfcc

Please sign in to comment.