email_domain_checker 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,25 +1,38 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "resolv"
4
+ require_relative "config"
4
5
 
5
6
  module EmailDomainChecker
6
7
  class DnsResolver
7
8
  attr_reader :timeout
8
9
 
9
- def initialize(timeout: 5)
10
+ def initialize(timeout: 5, cache: nil)
10
11
  @timeout = timeout
12
+ @cache = cache
11
13
  end
12
14
 
13
15
  def has_mx_record?(domain)
14
- check_dns_record(domain, Resolv::DNS::Resource::IN::MX)
16
+ has_record?(domain, "mx", Resolv::DNS::Resource::IN::MX)
15
17
  end
16
18
 
17
19
  def has_a_record?(domain)
18
- check_dns_record(domain, Resolv::DNS::Resource::IN::A)
20
+ has_record?(domain, "a", Resolv::DNS::Resource::IN::A)
19
21
  end
20
22
 
21
23
  private
22
24
 
25
+ def has_record?(domain, record_type, resource_type)
26
+ cache_key = "#{record_type}:#{domain}"
27
+ if cache
28
+ cache.with(cache_key, ttl: cache_ttl) do
29
+ check_dns_record(domain, resource_type)
30
+ end
31
+ else
32
+ check_dns_record(domain, resource_type)
33
+ end
34
+ end
35
+
23
36
  def check_dns_record(domain, resource_type)
24
37
  resolver = create_resolver
25
38
 
@@ -36,5 +49,15 @@ module EmailDomainChecker
36
49
  resolver.timeouts = [timeout]
37
50
  resolver
38
51
  end
52
+
53
+ def cache
54
+ # Use instance variable if set, otherwise try to get from Config
55
+ return @cache if defined?(@cache) && !@cache.nil?
56
+ return Config.cache_adapter if Config.cache_enabled?
57
+ end
58
+
59
+ def cache_ttl
60
+ Config.cache_ttl
61
+ end
39
62
  end
40
63
  end
@@ -13,7 +13,8 @@ module EmailDomainChecker
13
13
  check_a: false,
14
14
  timeout: 5
15
15
  }.merge(options)
16
- @dns_resolver = DnsResolver.new(timeout: @options[:timeout])
16
+ cache = Config.cache_enabled? ? Config.cache_adapter : nil
17
+ @dns_resolver = DnsResolver.new(timeout: @options[:timeout], cache: cache)
17
18
  end
18
19
 
19
20
  def valid?(domain)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EmailDomainChecker
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.3"
5
5
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative "email_domain_checker/version"
4
4
  require_relative "email_domain_checker/config"
5
+ require_relative "email_domain_checker/cache"
5
6
  require_relative "email_domain_checker/normalizer"
6
7
  require_relative "email_domain_checker/dns_resolver"
7
8
  require_relative "email_domain_checker/domain_validator"
@@ -46,4 +47,35 @@ module EmailDomainChecker
46
47
  def self.configure(options = {}, &block)
47
48
  Config.configure(options, &block)
48
49
  end
50
+
51
+ # Clear all cached DNS validation results
52
+ def self.clear_cache
53
+ Config.clear_cache
54
+ end
55
+
56
+ # Clear cached DNS validation results for a specific domain
57
+ def self.clear_cache_for_domain(domain)
58
+ Config.clear_cache_for_domain(domain)
59
+ end
60
+
61
+ # Get cache adapter instance (returns nil if cache is disabled)
62
+ # @return [Cache::BaseAdapter, nil] Cache adapter instance
63
+ def self.cache
64
+ Config.cache_adapter
65
+ end
66
+
67
+ # Convenience method for cache.with (Rails-style)
68
+ # Only works if cache is enabled
69
+ # @param key [String] cache key
70
+ # @param ttl [Integer, nil] time to live in seconds
71
+ # @param force [Boolean] force cache refresh
72
+ # @yield Block to execute on cache miss
73
+ # @return [Object] cached value or block result
74
+ # @raise [ArgumentError] if cache is disabled or block is not given
75
+ def self.with_cache(key, ttl: nil, force: false, &block)
76
+ adapter = cache
77
+ raise ArgumentError, "Cache is not enabled. Please enable cache in configuration." unless adapter
78
+
79
+ adapter.with(key, ttl: ttl, force: force, &block)
80
+ end
49
81
  end
data/mkdocs.yml ADDED
@@ -0,0 +1,65 @@
1
+ site_name: EmailDomainChecker
2
+ site_description: Email address validation and domain checking library
3
+ site_url: https://tatematsu-k.github.io/email_domain_checker
4
+ repo_url: https://github.com/tatematsu-k/email_domain_checker
5
+ repo_name: email_domain_checker
6
+
7
+ theme:
8
+ name: material
9
+ palette:
10
+ - scheme: default
11
+ primary: indigo
12
+ accent: indigo
13
+ toggle:
14
+ icon: material/brightness-7
15
+ name: Switch to dark mode
16
+ - scheme: slate
17
+ primary: indigo
18
+ accent: indigo
19
+ toggle:
20
+ icon: material/brightness-4
21
+ name: Switch to light mode
22
+ features:
23
+ - navigation.tabs
24
+ - navigation.sections
25
+ - navigation.expand
26
+ - navigation.top
27
+ - search.suggest
28
+ - search.highlight
29
+ - content.code.copy
30
+ - content.code.annotate
31
+
32
+ markdown_extensions:
33
+ - pymdownx.highlight:
34
+ anchor_linenums: true
35
+ - pymdownx.inlinehilite
36
+ - pymdownx.snippets
37
+ - pymdownx.superfences:
38
+ custom_fences:
39
+ - name: mermaid
40
+ class: mermaid
41
+ format: !!python/name:pymdownx.superfences.fence_code_format
42
+ - admonition
43
+ - pymdownx.details
44
+ - pymdownx.tasklist:
45
+ custom_checkbox: true
46
+ - attr_list
47
+ - md_in_html
48
+
49
+ nav:
50
+ - Home: index.md
51
+ - Getting Started:
52
+ - Installation: getting-started/installation.md
53
+ - Quick Start: getting-started/quick-start.md
54
+ - Usage:
55
+ - Module-level Methods: usage/module-methods.md
56
+ - Checker Class: usage/checker-class.md
57
+ - ActiveModel Integration: usage/activemodel-integration.md
58
+ - Configuration:
59
+ - Configuration Options: configuration/options.md
60
+ - Test Mode: configuration/test-mode.md
61
+ - Cache Configuration: configuration/cache.md
62
+ - Contributing: contributing.md
63
+
64
+ plugins:
65
+ - search
data/requirements.txt ADDED
@@ -0,0 +1,2 @@
1
+ mkdocs>=1.5.0
2
+ mkdocs-material>=9.0.0
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: email_domain_checker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koki Tatematsu
@@ -77,9 +77,24 @@ files:
77
77
  - CHANGELOG.md
78
78
  - README.md
79
79
  - Rakefile
80
+ - docs-templates/index.html
81
+ - docs/configuration/cache.md
82
+ - docs/configuration/options.md
83
+ - docs/configuration/test-mode.md
84
+ - docs/contributing.md
85
+ - docs/getting-started/installation.md
86
+ - docs/getting-started/quick-start.md
87
+ - docs/index.md
88
+ - docs/usage/activemodel-integration.md
89
+ - docs/usage/checker-class.md
90
+ - docs/usage/module-methods.md
80
91
  - email_domain_checker.gemspec
81
92
  - lib/email_domain_checker.rb
82
93
  - lib/email_domain_checker/active_model_validator.rb
94
+ - lib/email_domain_checker/cache.rb
95
+ - lib/email_domain_checker/cache/base_adapter.rb
96
+ - lib/email_domain_checker/cache/memory_adapter.rb
97
+ - lib/email_domain_checker/cache/redis_adapter.rb
83
98
  - lib/email_domain_checker/checker.rb
84
99
  - lib/email_domain_checker/config.rb
85
100
  - lib/email_domain_checker/dns_resolver.rb
@@ -87,6 +102,8 @@ files:
87
102
  - lib/email_domain_checker/email_address_adapter.rb
88
103
  - lib/email_domain_checker/normalizer.rb
89
104
  - lib/email_domain_checker/version.rb
105
+ - mkdocs.yml
106
+ - requirements.txt
90
107
  homepage: https://github.com/tatematsu-k/email_domain_checker
91
108
  licenses:
92
109
  - MIT