Sha256: 8d987eda8937e48279e5e0d40fb80cd6ba208953043e411176d3ebf10bb72d8e
Contents?: true
Size: 774 Bytes
Versions: 30
Compression:
Stored size: 774 Bytes
Contents
# frozen_string_literal: true # Allows you to use PostgreSQL transaction advisory locks for application-level mutexes module Sequel::Plugins::Synchronize module ClassMethods # Watch Sequel::Synchronize#synchronize_with def synchronize_with(*args, &block) db.extension(:synchronize).synchronize_with(*args, &block) end end module InstanceMethods # Just like Sequel::Synchronize#synchronize_with, # but name, which is joined from args, is combined with table_name and primary_key def synchronize(*args, **options) self.class.synchronize_with(lock_key_for(args), **options) { yield(reload) } end private def lock_key_for(args) [self.class.table_name, self[primary_key], *args].flatten.join("-") end end end
Version data entries
30 entries across 30 versions & 1 rubygems