Module: EmailDomainChecker

Defined in:
lib/email_domain_checker.rb,
lib/email_domain_checker/cache.rb,
lib/email_domain_checker/config.rb,
lib/email_domain_checker/checker.rb,
lib/email_domain_checker/version.rb,
lib/email_domain_checker/normalizer.rb,
lib/email_domain_checker/dns_resolver.rb,
lib/email_domain_checker/domain_validator.rb,
lib/email_domain_checker/cache/base_adapter.rb,
lib/email_domain_checker/cache/redis_adapter.rb,
lib/email_domain_checker/cache/memory_adapter.rb,
lib/email_domain_checker/email_address_adapter.rb,
lib/email_domain_checker/active_model_validator.rb

Defined Under Namespace

Modules: Cache Classes: Checker, Config, DnsResolver, DomainCheckValidator, DomainValidator, EmailAddressAdapter, Error, Normalizer

Constant Summary collapse

VERSION =
"0.1.4"

Class Method Summary collapse

Class Method Details

.cacheCache::BaseAdapter?

Get cache adapter instance (returns nil if cache is disabled)

Returns:



63
64
65
# File 'lib/email_domain_checker.rb', line 63

def self.cache
  Config.cache_adapter
end

.clear_cacheObject

Clear all cached DNS validation results



52
53
54
# File 'lib/email_domain_checker.rb', line 52

def self.clear_cache
  Config.clear_cache
end

.clear_cache_for_domain(domain) ⇒ Object

Clear cached DNS validation results for a specific domain



57
58
59
# File 'lib/email_domain_checker.rb', line 57

def self.clear_cache_for_domain(domain)
  Config.clear_cache_for_domain(domain)
end

.configure(options = {}, &block) ⇒ Object

Configure default options



47
48
49
# File 'lib/email_domain_checker.rb', line 47

def self.configure(options = {}, &block)
  Config.configure(options, &block)
end

.domain_valid?(email, options = {}) ⇒ Boolean

Convenience method for domain validation only

Returns:

  • (Boolean)


37
38
39
# File 'lib/email_domain_checker.rb', line 37

def self.domain_valid?(email, options = {})
  Checker.new(email, validate_format: false, **options).domain_valid?
end

.format_valid?(email) ⇒ Boolean

Convenience method for format validation only

Returns:

  • (Boolean)


32
33
34
# File 'lib/email_domain_checker.rb', line 32

def self.format_valid?(email)
  Checker.new(email, validate_domain: false).format_valid?
end

.normalize(email) ⇒ Object

Convenience method for normalization



42
43
44
# File 'lib/email_domain_checker.rb', line 42

def self.normalize(email)
  Normalizer.normalize(email)
end

.valid?(email, options = {}) ⇒ Boolean

Convenience method for quick validation

Returns:

  • (Boolean)


27
28
29
# File 'lib/email_domain_checker.rb', line 27

def self.valid?(email, options = {})
  Checker.new(email, options).valid?
end

.with_cache(key, ttl: nil, force: false) { ... } ⇒ Object

Convenience method for cache.with (Rails-style) Only works if cache is enabled

Parameters:

  • key (String)

    cache key

  • ttl (Integer, nil) (defaults to: nil)

    time to live in seconds

  • force (Boolean) (defaults to: false)

    force cache refresh

Yields:

  • Block to execute on cache miss

Returns:

  • (Object)

    cached value or block result

Raises:

  • (ArgumentError)

    if cache is disabled or block is not given



75
76
77
78
79
80
# File 'lib/email_domain_checker.rb', line 75

def self.with_cache(key, ttl: nil, force: false, &block)
  adapter = cache
  raise ArgumentError, "Cache is not enabled. Please enable cache in configuration." unless adapter

  adapter.with(key, ttl: ttl, force: force, &block)
end