Sha256: c2749e6e8931b86f92a09972f6edbec1f542af8f01da8cc49da2fa622fdf22d5
Contents?: true
Size: 747 Bytes
Versions: 4
Compression:
Stored size: 747 Bytes
Contents
# -*- encoding : utf-8 -*- module Mongoid module Userstamp module User extend ActiveSupport::Concern included do include Mongoid::Timestamps def current? !Thread.current[:user].nil? && self.id == Thread.current[:user].id end end module ClassMethods def current Thread.current[:user] end def current=(value) Thread.current[:user] = value end def do_as(user, &block) old = self.current begin self.current = user response = block.call unless block.nil? ensure self.current = old end response end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems