Sha256: f9380065914c25817e4d7b7abfbb296cda7e82e5baa3bc020c06c35afa5591c8

Contents?: true

Size: 711 Bytes

Versions: 3

Compression:

Stored size: 711 Bytes

Contents

# -*- encoding : utf-8 -*-
module Mongoid
  module Userstamp
    module User
      extend ActiveSupport::Concern

      included do
        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

3 entries across 3 versions & 2 rubygems

Version Path
glebtv_mongoid_userstamp-0.4.1 lib/mongoid/userstamp/user.rb
glebtv_mongoid_userstamp-0.4.0 lib/mongoid/userstamp/user.rb
mongoid_userstamp-0.3.0 lib/mongoid/userstamp/user.rb