Class: ValidEmail2::Dns
- Inherits:
-
Object
- Object
- ValidEmail2::Dns
- Defined in:
- lib/valid_email2/dns.rb
Defined Under Namespace
Classes: CacheEntry
Constant Summary collapse
- MAX_CACHE_SIZE =
1_000- CACHE =
{}
Class Method Summary collapse
Instance Method Summary collapse
- #a_servers(domain) ⇒ Object
-
#initialize(dns_timeout = 5, dns_nameserver = nil) ⇒ Dns
constructor
A new instance of Dns.
- #mx_servers(domain) ⇒ Object
Constructor Details
#initialize(dns_timeout = 5, dns_nameserver = nil) ⇒ Dns
Returns a new instance of Dns.
20 21 22 23 |
# File 'lib/valid_email2/dns.rb', line 20 def initialize(dns_timeout = 5, dns_nameserver = nil) @dns_timeout = dns_timeout @dns_nameserver = dns_nameserver end |
Class Method Details
.clear_cache ⇒ Object
16 17 18 |
# File 'lib/valid_email2/dns.rb', line 16 def self.clear_cache CACHE.clear end |
.prune_cache ⇒ Object
10 11 12 13 14 |
# File 'lib/valid_email2/dns.rb', line 10 def self.prune_cache entries_sorted_by_cached_at_asc = CACHE.sort_by { |key, data| data.cached_at } entries_to_remove = entries_sorted_by_cached_at_asc.first(CACHE.size - MAX_CACHE_SIZE) entries_to_remove.each { |key, _value| CACHE.delete(key) } end |
Instance Method Details
#a_servers(domain) ⇒ Object
29 30 31 |
# File 'lib/valid_email2/dns.rb', line 29 def a_servers(domain) fetch(domain, Resolv::DNS::Resource::IN::A) end |
#mx_servers(domain) ⇒ Object
25 26 27 |
# File 'lib/valid_email2/dns.rb', line 25 def mx_servers(domain) fetch(domain, Resolv::DNS::Resource::IN::MX) end |