Sha256: b818ff4a787414ffc7e6166a8fe444a7df07cbb839ef400c4729db9534f12e91

Contents?: true

Size: 865 Bytes

Versions: 2

Compression:

Stored size: 865 Bytes

Contents

# frozen_string_literal: true

require "mongoid"

module OmniAuth
  module Identity
    module Models
      # Mongoid is an ORM adapter for MongoDB:
      #   https://github.com/mongodb/mongoid
      # NOTE: Mongoid is based on ActiveModel.
      module Mongoid
        def self.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

            def self.auth_key=(key)
              super
              validates_uniqueness_of(key, case_sensitive: false)
            end

            def self.locate(search_hash)
              where(search_hash).first
            end
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
omniauth-identity-3.1.1 lib/omniauth/identity/models/mongoid.rb
omniauth-identity-3.1.0 lib/omniauth/identity/models/mongoid.rb