Sha256: f15e358b1b77b60d5fba9e310052853f3970ae11b04287291f6994ad5cd988c6

Contents?: true

Size: 1.63 KB

Versions: 2

Compression:

Stored size: 1.63 KB

Contents

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_waiter
      self.save
      self.reload
      return super
    end

    def lock_used_by
      self.save
      self.reload
      return super
    end
    
    def lock_acquired_at
      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_waiter, :type => String, :default => nil
        field :lock_used_by, :type => String, :default => nil
        field :lock_acquired_at, :type => Time, :default => nil
        index [[:lock_acquired_at, -1]], :sparse => true
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mongoid-lock-0.0.9 lib/mongoid/lock.rb
mongoid-lock-0.0.8 lib/mongoid/lock.rb