Sha256: b9b9c408eafbe214229436a1693ee7ca449c71182ac7c1bfeb814cb880a4c0c1

Contents?: true

Size: 1.42 KB

Versions: 17

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

module Authlogic
  module ActsAsAuthentic
    module Queries
      # @api private
      class CaseSensitivity
        E_UNABLE_TO_DETERMINE_SENSITIVITY = <<~EOS
          Authlogic was unable to determine what case-sensitivity to use when
          searching for email/login. To specify a sensitivity, validate the
          uniqueness of the email/login and use the `case_sensitive` option,
          like this:

              validates :email, uniqueness: { case_sensitive: false }

          Authlogic will now perform a case-insensitive query.
        EOS

        # @api private
        def initialize(model_class, attribute)
          @model_class = model_class
          @attribute = attribute.to_sym
        end

        # @api private
        def sensitive?
          sensitive = uniqueness_validator_options[:case_sensitive]
          if sensitive.nil?
            ::Kernel.warn(E_UNABLE_TO_DETERMINE_SENSITIVITY)
            false
          else
            sensitive
          end
        end

        private

        # @api private
        def uniqueness_validator
          @model_class.validators.select { |v|
            v.is_a?(::ActiveRecord::Validations::UniquenessValidator) &&
              v.attributes == [@attribute]
          }.first
        end

        # @api private
        def uniqueness_validator_options
          uniqueness_validator&.options || {}
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
authlogic-6.4.3 lib/authlogic/acts_as_authentic/queries/case_sensitivity.rb
authlogic-nicho-6.6 lib/authlogic/acts_as_authentic/queries/case_sensitivity.rb
authlogic-nicho-6.5 lib/authlogic/acts_as_authentic/queries/case_sensitivity.rb
authlogic-6.4.2 lib/authlogic/acts_as_authentic/queries/case_sensitivity.rb
authlogic-6.4.1 lib/authlogic/acts_as_authentic/queries/case_sensitivity.rb
authlogic-6.4.0 lib/authlogic/acts_as_authentic/queries/case_sensitivity.rb
authlogic-6.3.0 lib/authlogic/acts_as_authentic/queries/case_sensitivity.rb
authlogic-6.2.0 lib/authlogic/acts_as_authentic/queries/case_sensitivity.rb
authlogic-5.2.0 lib/authlogic/acts_as_authentic/queries/case_sensitivity.rb
authlogic-6.1.0 lib/authlogic/acts_as_authentic/queries/case_sensitivity.rb
authlogic-6.0.0 lib/authlogic/acts_as_authentic/queries/case_sensitivity.rb
authlogic-5.1.0 lib/authlogic/acts_as_authentic/queries/case_sensitivity.rb
authlogic-5.0.4 lib/authlogic/acts_as_authentic/queries/case_sensitivity.rb
authlogic-5.0.3 lib/authlogic/acts_as_authentic/queries/case_sensitivity.rb
authlogic-5.0.2 lib/authlogic/acts_as_authentic/queries/case_sensitivity.rb
authlogic-5.0.1 lib/authlogic/acts_as_authentic/queries/case_sensitivity.rb
authlogic-5.0.0 lib/authlogic/acts_as_authentic/queries/case_sensitivity.rb