Sha256: 915c5c716a1861108317125ca3c4a4ee612d6c3d1edbcec4fcdc98e6549c7248

Contents?: true

Size: 761 Bytes

Versions: 4

Compression:

Stored size: 761 Bytes

Contents

module Mongoid
  module Userstamps
    module User
      extend ActiveSupport::Concern

      included do
        Mongoid::Userstamps::Config.add_user_class(self)
      end

      def current?
        id == self.class.current.try(:id)
      end

      class_methods do
        def current
          Mongoid::Userstamps::Config.current_user(self)
        end

        def current=(value)
          Mongoid::Userstamps::Config.set_current_user(self, value)
        end

        def sudo(user)
          old = current
          self.current = user
          yield
        ensure
          self.current = old
        end

        def userstamps_user
          @userstamps_user ||= Mongoid::Userstamps::Config::User.new(self)
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mongoid-userstamps-3.4.1 lib/mongoid/userstamps/user.rb
mongoid-userstamps-3.4.0 lib/mongoid/userstamps/user.rb
mongoid-userstamps-3.3.0 lib/mongoid/userstamps/user.rb
mongoid-userstamps-3.2.1 lib/mongoid/userstamps/user.rb