Sha256: ff4dc34ac26f7b87b409b273f6775924a0224369885cb2575969d6ad111fc773

Contents?: true

Size: 603 Bytes

Versions: 2

Compression:

Stored size: 603 Bytes

Contents

# frozen_string_literal: true

class DeviseJwtAuthEmailValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, value)
    unless value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
      record.errors[attribute] << email_invalid_message
    end
  end

  private

  def email_invalid_message
    # Try strictly set message:
    message = options[:message]

    if message.nil?
      # Try DeviceTokenAuth translations or fallback to ActiveModel translations
      message = I18n.t(:'errors.messages.not_email', default: :'errors.messages.invalid')
    end

    message
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
devise_jwt_auth-0.1.1 app/validators/devise_jwt_auth_email_validator.rb
devise_jwt_auth-0.1.0 app/validators/devise_jwt_auth_email_validator.rb