Sha256: 313aac4889bf681a49410c782d9049ae0fd67196c114982a2dfe3b818ffcd365

Contents?: true

Size: 1.21 KB

Versions: 2

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

require 'nobrainer'

module OmniAuth
  module Identity
    module Models
      # http://sequel.jeremyevans.net/ an SQL ORM
      # NOTE: Sequel is *not* based on ActiveModel, but supports the API we need, except for `persisted?`:
      # * create
      # * save
      module Sequel
        def self.included(base)
          base.class_eval do
            # NOTE: Using the deprecated :validations_class_methods because it defines
            #       validates_confirmation_of, while current :validation_helpers does not.
            # plugin :validation_helpers
            plugin :validation_class_methods

            include ::OmniAuth::Identity::Model
            include ::OmniAuth::Identity::SecurePassword

            has_secure_password

            alias_method :persisted?, :valid?

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

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

            def persisted?
              exists?
            end

            def save
              super
            end
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
omniauth-identity-3.0.8 lib/omniauth/identity/models/sequel.rb
omniauth-identity-3.0.7 lib/omniauth/identity/models/sequel.rb