Module: OmniAuth::Identity::Models::CouchPotatoModule
- Defined in:
- lib/omniauth/identity/models/couch_potato.rb
Overview
CouchPotato is based on ActiveModel, so validations are enabled by default.
CouchPotato::Persistence must be included before OmniAuth::Identity::Models::CouchPotatoModule.
Includes “Module” in the name for invalid legacy reasons. Rename only with a major version bump.
CouchPotato is an ORM adapter for CouchDB:
https://github.com/langalex/couch_potato
This module provides OmniAuth Identity functionality for CouchPotato 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.
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 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/omniauth/identity/models/couch_potato.rb', line 42 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 CouchPotato is ActiveModel based. has_secure_password # @!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::CouchPotatoModule # self.auth_key = :email # end def self.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 [Object, nil] the first matching record or nil # @example # User.locate(email: 'user@example.com') def self.locate(search_hash) where(search_hash).first end # @!method save # Saves the document to the CouchDB database. # # @return [Boolean] true if saved successfully, false otherwise # @example # user = User.new(email: 'user@example.com', password: 'password') # user.save # => true def save CouchPotato.database.save_document(self) end end end |