Sha256: 7790cc2c8c90d3419e3b039785d622d9b492e3a46829127b7663128f13cf818a
Contents?: true
Size: 1.03 KB
Versions: 1
Compression:
Stored size: 1.03 KB
Contents
# Tried desperately to monkeypatch the polymorphic connection object, # but rails autoloading is too clever by half. Pull requests are welcome. # Think of this module as a hipster, using "case" ironically. require 'with_advisory_lock/base' require 'with_advisory_lock/mysql' require 'with_advisory_lock/postgresql' require 'with_advisory_lock/flock' require 'active_support/concern' module WithAdvisoryLock module Concern extend ActiveSupport::Concern def with_advisory_lock(lock_name, timeout_seconds=nil, &block) self.class.with_advisory_lock(lock_name, timeout_seconds, &block) end module ClassMethods def with_advisory_lock(lock_name, timeout_seconds=nil, &block) case (connection.adapter_name.downcase) when "postgresql" WithAdvisoryLock::PostgreSQL when "mysql", "mysql2" WithAdvisoryLock::MySQL else WithAdvisoryLock::Flock end.new(connection, lock_name, timeout_seconds).with_advisory_lock(&block) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
with_advisory_lock-0.0.1 | lib/with_advisory_lock/concern.rb |