Skip to content

Commit

Permalink
Refactored out class convenience methods
Browse files Browse the repository at this point in the history
  • Loading branch information
msaspence committed Feb 24, 2014
1 parent 29d533a commit d2f8da9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 25 deletions.
28 changes: 3 additions & 25 deletions lib/mongo-lock.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
require 'mongo-lock/configuration'
require 'mongo-lock/queries'
require 'mongo-lock/class_convenience_methods'

module Mongo
class Lock

extend Mongo::Lock::ClassConvenienceMethods

class NotAcquiredError < StandardError ; end
class NotReleasedError < StandardError ; end
class NotExtendedError < StandardError ; end
Expand Down Expand Up @@ -36,31 +39,6 @@ def self.configuration
end
end

def self.init_and_send key, options = {}, method
lock = self.new(key, options)
lock.send(method)
lock
end

def self.acquire key, options = {}
init_and_send key, options, :acquire
end

def self.release key, options = {}
init_and_send key, options, :release
end

def self.acquire! key, options = {}
init_and_send key, options, :acquire!
end

def self.release! key, options = {}
init_and_send key, options, :release!
end

def self.available? key, options = {}
init_and_send key, options, :available?
end

def self.release_all options = {}
if options.include? :collection
Expand Down
33 changes: 33 additions & 0 deletions lib/mongo-lock/class_convenience_methods.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module Mongo
class Lock
module ClassConvenienceMethods

def init_and_send key, options = {}, method
lock = Mongo::Lock.new(key, options)
lock.send(method)
lock
end

def acquire key, options = {}
init_and_send key, options, :acquire
end

def release key, options = {}
init_and_send key, options, :release
end

def acquire! key, options = {}
init_and_send key, options, :acquire!
end

def release! key, options = {}
init_and_send key, options, :release!
end

def available? key, options = {}
init_and_send key, options, :available?
end

end
end
end

0 comments on commit d2f8da9

Please sign in to comment.