Sha256: 83a4b44ee60b7f68e32776f07e202fe3ebccc8f6d0e65818ccc36d7f55e64aba

Contents?: true

Size: 976 Bytes

Versions: 2

Compression:

Stored size: 976 Bytes

Contents

# frozen_string_literal: true

require 'email_detected/version'

module EmailDetected
  require 'email_detected/config'
  require 'email_detected/checker'
  require 'email_detected/messages'
  require 'email_detected/validates_exist_email'

  VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i.freeze

  def self.exist?(email)
    return true if config.test_mode
    unless email.match VALID_EMAIL_REGEX
      return { status: false, message: 'The email address invalid.' }
    end

    email_detected = EmailDetected::Checker.run(email)
    if email_detected.invalid?
      resp = { status: false, message: email_detected.errors.first }
    else
      message = email_detected.errors.first || 'The email address has already been registered.'
      resp = { status: true, message: message }
    end
    resp
  end

  def self.config(&block)
    if block_given?
      block.call(EmailDetected::Config)
    else
      EmailDetected::Config
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
email_detected-0.1.3 lib/email_detected.rb
email_detected-0.1.2 lib/email_detected.rb