Class: EmailDomainChecker::Config
- Inherits:
-
Object
- Object
- EmailDomainChecker::Config
- Defined in:
- lib/email_domain_checker/config.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ validate_format: true, validate_domain: true, check_mx: true, check_a: false, timeout: 5 }.freeze
Class Attribute Summary collapse
-
.blacklist_domains ⇒ Object
Returns the value of attribute blacklist_domains.
-
.cache_adapter ⇒ Object
Returns the value of attribute cache_adapter.
-
.cache_adapter_instance ⇒ Object
Returns the value of attribute cache_adapter_instance.
-
.cache_enabled ⇒ Object
Returns the value of attribute cache_enabled.
-
.cache_ttl ⇒ Object
Returns the value of attribute cache_ttl.
-
.cache_type ⇒ Object
Returns the value of attribute cache_type.
-
.default_options ⇒ Object
Returns the value of attribute default_options.
-
.domain_checker ⇒ Object
Returns the value of attribute domain_checker.
-
.redis_client ⇒ Object
Returns the value of attribute redis_client.
-
.test_mode ⇒ Object
Returns the value of attribute test_mode.
-
.whitelist_domains ⇒ Object
Returns the value of attribute whitelist_domains.
Instance Attribute Summary collapse
-
#blacklist_domains ⇒ Object
Returns the value of attribute blacklist_domains.
-
#cache_adapter_instance ⇒ Object
Returns the value of attribute cache_adapter_instance.
-
#cache_enabled ⇒ Object
Returns the value of attribute cache_enabled.
-
#cache_ttl ⇒ Object
Returns the value of attribute cache_ttl.
-
#cache_type ⇒ Object
Returns the value of attribute cache_type.
-
#domain_checker ⇒ Object
Returns the value of attribute domain_checker.
-
#redis_client ⇒ Object
Returns the value of attribute redis_client.
-
#test_mode ⇒ Object
Returns the value of attribute test_mode.
-
#whitelist_domains ⇒ Object
Returns the value of attribute whitelist_domains.
Class Method Summary collapse
- .cache_enabled? ⇒ Boolean
- .clear_cache ⇒ Object
- .clear_cache_for_domain(domain) ⇒ Object
- .configure(options = {}, &block) ⇒ Object
- .reset ⇒ Object
- .reset_cache_adapter_if_needed ⇒ Object
- .reset_cache_adapter_if_redis ⇒ Object
- .reset_cache_adapter_on_enabled_change(new_value, old_value) ⇒ Object
- .test_mode? ⇒ Boolean
- .validate_cache_adapter_instance!(instance) ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/email_domain_checker/config.rb', line 124 def initialize @test_mode = self.class.test_mode || false @cache_enabled = self.class.cache_enabled.nil? ? true : self.class.cache_enabled @cache_type = self.class.cache_type || :memory @cache_ttl = self.class.cache_ttl || 3600 @cache_adapter_instance = self.class.cache_adapter_instance @redis_client = self.class.redis_client @blacklist_domains = self.class.blacklist_domains || [] @whitelist_domains = self.class.whitelist_domains || [] @domain_checker = self.class.domain_checker end |
Class Attribute Details
.blacklist_domains ⇒ Object
Returns the value of attribute blacklist_domains.
16 17 18 |
# File 'lib/email_domain_checker/config.rb', line 16 def blacklist_domains @blacklist_domains end |
.cache_adapter ⇒ Object
Returns the value of attribute cache_adapter.
16 17 18 |
# File 'lib/email_domain_checker/config.rb', line 16 def cache_adapter @cache_adapter end |
.cache_adapter_instance ⇒ Object
Returns the value of attribute cache_adapter_instance.
16 17 18 |
# File 'lib/email_domain_checker/config.rb', line 16 def cache_adapter_instance @cache_adapter_instance end |
.cache_enabled ⇒ Object
Returns the value of attribute cache_enabled.
16 17 18 |
# File 'lib/email_domain_checker/config.rb', line 16 def cache_enabled @cache_enabled end |
.cache_ttl ⇒ Object
Returns the value of attribute cache_ttl.
16 17 18 |
# File 'lib/email_domain_checker/config.rb', line 16 def cache_ttl @cache_ttl end |
.cache_type ⇒ Object
Returns the value of attribute cache_type.
16 17 18 |
# File 'lib/email_domain_checker/config.rb', line 16 def cache_type @cache_type end |
.default_options ⇒ Object
Returns the value of attribute default_options.
16 17 18 |
# File 'lib/email_domain_checker/config.rb', line 16 def end |
.domain_checker ⇒ Object
Returns the value of attribute domain_checker.
16 17 18 |
# File 'lib/email_domain_checker/config.rb', line 16 def domain_checker @domain_checker end |
.redis_client ⇒ Object
Returns the value of attribute redis_client.
16 17 18 |
# File 'lib/email_domain_checker/config.rb', line 16 def redis_client @redis_client end |
.test_mode ⇒ Object
Returns the value of attribute test_mode.
16 17 18 |
# File 'lib/email_domain_checker/config.rb', line 16 def test_mode @test_mode end |
.whitelist_domains ⇒ Object
Returns the value of attribute whitelist_domains.
16 17 18 |
# File 'lib/email_domain_checker/config.rb', line 16 def whitelist_domains @whitelist_domains end |
Instance Attribute Details
#blacklist_domains ⇒ Object
Returns the value of attribute blacklist_domains.
122 123 124 |
# File 'lib/email_domain_checker/config.rb', line 122 def blacklist_domains @blacklist_domains end |
#cache_adapter_instance ⇒ Object
Returns the value of attribute cache_adapter_instance.
122 123 124 |
# File 'lib/email_domain_checker/config.rb', line 122 def cache_adapter_instance @cache_adapter_instance end |
#cache_enabled ⇒ Object
Returns the value of attribute cache_enabled.
122 123 124 |
# File 'lib/email_domain_checker/config.rb', line 122 def cache_enabled @cache_enabled end |
#cache_ttl ⇒ Object
Returns the value of attribute cache_ttl.
122 123 124 |
# File 'lib/email_domain_checker/config.rb', line 122 def cache_ttl @cache_ttl end |
#cache_type ⇒ Object
Returns the value of attribute cache_type.
122 123 124 |
# File 'lib/email_domain_checker/config.rb', line 122 def cache_type @cache_type end |
#domain_checker ⇒ Object
Returns the value of attribute domain_checker.
122 123 124 |
# File 'lib/email_domain_checker/config.rb', line 122 def domain_checker @domain_checker end |
#redis_client ⇒ Object
Returns the value of attribute redis_client.
122 123 124 |
# File 'lib/email_domain_checker/config.rb', line 122 def redis_client @redis_client end |
#test_mode ⇒ Object
Returns the value of attribute test_mode.
122 123 124 |
# File 'lib/email_domain_checker/config.rb', line 122 def test_mode @test_mode end |
#whitelist_domains ⇒ Object
Returns the value of attribute whitelist_domains.
122 123 124 |
# File 'lib/email_domain_checker/config.rb', line 122 def whitelist_domains @whitelist_domains end |
Class Method Details
.cache_enabled? ⇒ Boolean
52 53 54 |
# File 'lib/email_domain_checker/config.rb', line 52 def cache_enabled? @cache_enabled == true end |
.clear_cache ⇒ Object
78 79 80 |
# File 'lib/email_domain_checker/config.rb', line 78 def clear_cache cache_adapter&.clear end |
.clear_cache_for_domain(domain) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/email_domain_checker/config.rb', line 82 def clear_cache_for_domain(domain) return unless cache_enabled? adapter = cache_adapter return unless adapter # Clear both MX and A record cache entries dns_cache_keys_for_domain(domain).each do |key| adapter.delete(key) end end |
.configure(options = {}, &block) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/email_domain_checker/config.rb', line 18 def configure( = {}, &block) if block_given? config_instance = new block.call(config_instance) = DEFAULT_OPTIONS.merge() config_instance else = DEFAULT_OPTIONS.merge() new end end |
.reset ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/email_domain_checker/config.rb', line 30 def reset = DEFAULT_OPTIONS.dup @test_mode = false @cache_enabled = true @cache_type = :memory @cache_ttl = 3600 @cache_adapter = nil @cache_adapter_instance = nil @redis_client = nil @blacklist_domains = [] @whitelist_domains = [] @domain_checker = nil end |
.reset_cache_adapter_if_needed ⇒ Object
94 95 96 97 98 99 |
# File 'lib/email_domain_checker/config.rb', line 94 def reset_cache_adapter_if_needed # Reset cache adapter when changing cache type (unless custom instance is set) @cache_adapter = nil unless @cache_adapter_instance # Clear cache_adapter_instance if setting a type (Symbol or String), not a Class @cache_adapter_instance = nil if @cache_type.is_a?(Symbol) || @cache_type.is_a?(String) end |
.reset_cache_adapter_if_redis ⇒ Object
105 106 107 |
# File 'lib/email_domain_checker/config.rb', line 105 def reset_cache_adapter_if_redis @cache_adapter = nil if @cache_type == :redis end |
.reset_cache_adapter_on_enabled_change(new_value, old_value) ⇒ Object
101 102 103 |
# File 'lib/email_domain_checker/config.rb', line 101 def reset_cache_adapter_on_enabled_change(new_value, old_value) @cache_adapter = nil if new_value != old_value end |
.test_mode? ⇒ Boolean
48 49 50 |
# File 'lib/email_domain_checker/config.rb', line 48 def test_mode? @test_mode == true end |
.validate_cache_adapter_instance!(instance) ⇒ Object
109 110 111 112 113 |
# File 'lib/email_domain_checker/config.rb', line 109 def validate_cache_adapter_instance!(instance) unless instance.nil? || instance.is_a?(Cache::BaseAdapter) raise ArgumentError, "cache_adapter_instance must be an instance of EmailDomainChecker::Cache::BaseAdapter or nil" end end |