Sha256: af385ca97c9350b11db360d1a030990bea28afd2e98ce0729148b729fc8a923d

Contents?: true

Size: 869 Bytes

Versions: 1

Compression:

Stored size: 869 Bytes

Contents

module Devise # :nodoc:
  module Models # :nodoc:

    # PasswordValidatable takes care of password validation for the password_regex
    module PasswordValidatable

      def self.include(base) # :nodoc:
        base.extend ClassMethods
        assert_password_validations_api!(base)

        base.class_eval do
          # validates password
          validates :password, :format => password_regex, :if => :password_required?
        end
      end

      def self.assert_password_validations_api!(base) # :nodoc:
        raise "Could not use PasswordValidatable on #{base}" unless base.respond_to?(:validates)
      end

      protected

      def password_required?
        !persisted? || !password.nil? || !password_confirmation.nil?
      end

      module ClassMethods # :nodoc:
        ::Devise::Models.config(self, :password_regex)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vizjerai-devise_security_extension-0.3.2 lib/devise_security_extension/models/password_validatable.rb