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 # => Add special fields for use field :lock_used_by, :type => String, :default => nil end end end end