class Truemail::Configuration
Constants
- DEFAULT_CONNECTION_ATTEMPTS
- DEFAULT_CONNECTION_TIMEOUT
- DEFAULT_LOGGER_OPTIONS
- DEFAULT_RESPONSE_TIMEOUT
- DEFAULT_VALIDATION_TYPE
- SETTERS
Attributes
default_validation_type[R]
logger[R]
not_rfc_mx_lookup_flow[RW]
smtp_fail_fast[RW]
smtp_safe_check[RW]
validation_type_by_domain[R]
verifier_domain[R]
verifier_email[R]
whitelist_validation[RW]
Public Class Methods
new(&block)
click to toggle source
# File lib/truemail/configuration.rb, line 31 def initialize(&block) instance_initializer.each do |instace_variable, value| instance_variable_set(:"@#{instace_variable}", value) end tap(&block) if block end
Public Instance Methods
argument_consistent?(method, argument)
click to toggle source
# File lib/truemail/configuration.rb, line 59 def argument_consistent?(method, argument) case argument when ::Array then items_match_regex?(argument, regex_by_method(method)) when ::Integer then argument.positive? when ::Regexp then true end end
complete?()
click to toggle source
# File lib/truemail/configuration.rb, line 85 def complete? !!verifier_email end
default_validation_type=(argument)
click to toggle source
# File lib/truemail/configuration.rb, line 49 def default_validation_type=(argument) raise_unless(argument, __method__, argument.is_a?(::Symbol) && Truemail::Validator::VALIDATION_TYPES.include?(argument)) @default_validation_type = argument end
logger=(options)
click to toggle source
# File lib/truemail/configuration.rb, line 74 def logger=(options) tracking_event, stdout, log_absolute_path = logger_options(options) valid_event = Truemail::Log::Event::TRACKING_EVENTS.key?(tracking_event) stdout_only = stdout && log_absolute_path.nil? file_only = log_absolute_path.is_a?(::String) both_types = stdout && file_only argument_info = valid_event ? log_absolute_path : tracking_event raise_unless(argument_info, __method__, valid_event && (stdout_only || file_only || both_types)) @logger = Truemail::Logger.new(tracking_event, stdout, log_absolute_path) end
validation_type_for=(settings)
click to toggle source
# File lib/truemail/configuration.rb, line 54 def validation_type_for=(settings) validate_validation_type(settings) validation_type_by_domain.merge!(settings) end
verifier_domain=(domain)
click to toggle source
# File lib/truemail/configuration.rb, line 44 def verifier_domain=(domain) validate_arguments(domain, __method__) @verifier_domain = domain.downcase end
verifier_email=(email)
click to toggle source
# File lib/truemail/configuration.rb, line 38 def verifier_email=(email) validate_arguments(email, __method__) @verifier_email = email.downcase default_verifier_domain end
Private Instance Methods
check_validation_type(validation_type)
click to toggle source
# File lib/truemail/configuration.rb, line 138 def check_validation_type(validation_type) raise_unless(validation_type, 'validation type', Truemail::Validator::VALIDATION_TYPES.include?(validation_type)) end
default_verifier_domain()
click to toggle source
# File lib/truemail/configuration.rb, line 124 def default_verifier_domain self.verifier_domain ||= verifier_email[Truemail::RegexConstant::REGEX_EMAIL_PATTERN, 3] end
instance_initializer()
click to toggle source
# File lib/truemail/configuration.rb, line 91 def instance_initializer # rubocop:disable Metrics/MethodLength { email_pattern: Truemail::RegexConstant::REGEX_EMAIL_PATTERN, smtp_error_body_pattern: Truemail::RegexConstant::REGEX_SMTP_ERROR_BODY_PATTERN, connection_timeout: Truemail::Configuration::DEFAULT_CONNECTION_TIMEOUT, response_timeout: Truemail::Configuration::DEFAULT_RESPONSE_TIMEOUT, connection_attempts: Truemail::Configuration::DEFAULT_CONNECTION_ATTEMPTS, default_validation_type: Truemail::Configuration::DEFAULT_VALIDATION_TYPE, validation_type_by_domain: {}, whitelisted_domains: [], whitelist_validation: false, blacklisted_domains: [], blacklisted_mx_ip_addresses: [], dns: [], not_rfc_mx_lookup_flow: false, smtp_fail_fast: false, smtp_safe_check: false } end
items_match_regex?(items, regex_pattern)
click to toggle source
# File lib/truemail/configuration.rb, line 134 def items_match_regex?(items, regex_pattern) items.all? { |item| match_regex?(regex_pattern, item) } end
logger_options(current_options)
click to toggle source
# File lib/truemail/configuration.rb, line 150 def logger_options(current_options) Truemail::Configuration::DEFAULT_LOGGER_OPTIONS.merge(current_options).values end
match_regex?(regex_pattern, object)
click to toggle source
# File lib/truemail/configuration.rb, line 115 def match_regex?(regex_pattern, object) regex_pattern.match?(object.to_s) end
raise_unless(argument_context, argument_name, condition)
click to toggle source
# File lib/truemail/configuration.rb, line 111 def raise_unless(argument_context, argument_name, condition) raise Truemail::ArgumentError.new(argument_context, argument_name) unless condition end
regex_by_method(method)
click to toggle source
# File lib/truemail/configuration.rb, line 128 def regex_by_method(method) return Truemail::RegexConstant::REGEX_IP_ADDRESS_PATTERN if method.eql?(:blacklisted_mx_ip_addresses) return Truemail::RegexConstant::REGEX_DNS_SERVER_ADDRESS_PATTERN if method.eql?(:dns) Truemail::RegexConstant::REGEX_DOMAIN_PATTERN end
validate_arguments(argument, method)
click to toggle source
# File lib/truemail/configuration.rb, line 119 def validate_arguments(argument, method) regex_pattern = Truemail::RegexConstant.const_get("regex_#{method[/\A.+_(.+)=\z/, 1]}_pattern".upcase) raise_unless(argument, method, match_regex?(regex_pattern, argument)) end
validate_validation_type(settings)
click to toggle source
# File lib/truemail/configuration.rb, line 142 def validate_validation_type(settings) raise_unless(settings, 'hash with settings', settings.is_a?(::Hash)) settings.each do |domain, validation_type| raise_unless(domain, 'domain', match_regex?(Truemail::RegexConstant::REGEX_DOMAIN_PATTERN, domain)) check_validation_type(validation_type) end end