Module: OmniAuth::Identity::Models::Mongoid
- Defined in:
- lib/omniauth/identity/models/mongoid.rb
Overview
Note:
Mongoid is based on ActiveModel, so validations are enabled by default.
Mongoid is an ORM adapter for MongoDB: github.com/mongodb/mongoid
This module provides OmniAuth Identity functionality for Mongoid models, including secure password handling and authentication key management.
Class Method Summary collapse
-
.included(base) ⇒ void
Called when this module is included in a model class.
Class Method Details
.included(base) ⇒ void
This method returns an undefined value.
Called when this module is included in a model class.
This method extends the base class with OmniAuth Identity functionality, including secure password support and authentication key validation.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/omniauth/identity/models/mongoid.rb', line 41 def included(base) base.class_eval do include(::OmniAuth::Identity::Model) include(::OmniAuth::Identity::SecurePassword) # validations: true (default) incurs a dependency on ActiveModel, but Mongoid is ActiveModel based. has_secure_password class << self # @!method self.auth_key=(key) # Sets the authentication key for the model and adds uniqueness validation. # # @param key [Symbol, String] the attribute to use as the authentication key # @return [void] # @example # class User # include OmniAuth::Identity::Models::Mongoid # self.auth_key = :email # end def auth_key=(key) super validates_uniqueness_of(key, case_sensitive: false) end # @!method self.locate(search_hash) # Finds a record by the given search criteria. # # @param search_hash [Hash] the attributes to search for # @return [Mongoid::Document, nil] the first matching record or nil # @example # User.locate(email: 'user@example.com') def locate(search_hash) where(search_hash).first end end end end |