Class: EmailDomainChecker::DomainValidator
- Inherits:
-
Object
- Object
- EmailDomainChecker::DomainValidator
- Defined in:
- lib/email_domain_checker/domain_validator.rb
Instance Attribute Summary collapse
-
#dns_resolver ⇒ Object
readonly
Returns the value of attribute dns_resolver.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ DomainValidator
constructor
A new instance of DomainValidator.
- #valid?(domain) ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ DomainValidator
Returns a new instance of DomainValidator.
10 11 12 13 14 15 16 17 18 |
# File 'lib/email_domain_checker/domain_validator.rb', line 10 def initialize( = {}) = { check_mx: true, check_a: false, timeout: 5 }.merge() cache = Config.cache_enabled? ? Config.cache_adapter : nil @dns_resolver = DnsResolver.new(timeout: [:timeout], cache: cache) end |
Instance Attribute Details
#dns_resolver ⇒ Object (readonly)
Returns the value of attribute dns_resolver.
8 9 10 |
# File 'lib/email_domain_checker/domain_validator.rb', line 8 def dns_resolver @dns_resolver end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/email_domain_checker/domain_validator.rb', line 8 def end |
Instance Method Details
#valid?(domain) ⇒ Boolean
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/email_domain_checker/domain_validator.rb', line 20 def valid?(domain) return false if domain.nil? || domain.empty? # Check whitelist first (if configured) unless Config.whitelist_domains.nil? || Config.whitelist_domains.empty? return whitelisted?(domain) end # Check blacklist return false if blacklisted?(domain) # Check custom domain checker if Config.domain_checker custom_result = Config.domain_checker.call(domain) return false unless custom_result end # Skip DNS checks if test mode is enabled return true if Config.test_mode? check_domain_records(domain) end |