require 'mongoid' require 'mongoid/lock/synch_methods' module Mongoid module Lock #------------------------------------------------------------------------------ # => Embedded class for Unsynchronized use Exceptions #------------------------------------------------------------------------------ class UnsynchronizedAccess < StandardError attr_reader :used_by def initialize(used_by, *args) @used_by = used_by super(*args) end end #------------------------------------------------------------------------------ # => Volatile Instance Attribute Accessor #------------------------------------------------------------------------------ def lock_used_by self.save self.reload return super end #------------------------------------------------------------------------------ # => Module inclusion hook #------------------------------------------------------------------------------ def self.included(base) super if defined?(super) base.class_eval do # => Extend Document, If not Already Extended unless (base.included_modules.include?(Mongoid::Document)) include Mongoid::Document end # => Add special field field :lock_used_by, :type => String, :default => nil end end end end