Class: Truemail::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/truemail/configuration.rb

Constant Summary collapse

DEFAULT_CONNECTION_TIMEOUT =
2
DEFAULT_RESPONSE_TIMEOUT =
2
DEFAULT_CONNECTION_ATTEMPTS =
2
DEFAULT_VALIDATION_TYPE =
:smtp
DEFAULT_SMTP_PORT =
25
DEFAULT_LOGGER_OPTIONS =
{ tracking_event: :error, stdout: false, log_absolute_path: nil }.freeze
SETTERS =
%i[
  email_pattern
  smtp_error_body_pattern
  connection_timeout
  response_timeout
  connection_attempts
  whitelisted_emails
  blacklisted_emails
  whitelisted_domains
  blacklisted_domains
  blacklisted_mx_ip_addresses
  dns
  smtp_port
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Configuration

Returns a new instance of Configuration.



35
36
37
38
39
40
# File 'lib/truemail/configuration.rb', line 35

def initialize(&block)
  instance_initializer.each do |instace_variable, value|
    instance_variable_set(:"@#{instace_variable}", value)
  end
  tap(&block) if block
end

Instance Attribute Details

#not_rfc_mx_lookup_flowObject

Returns the value of attribute not_rfc_mx_lookup_flow.



33
34
35
# File 'lib/truemail/configuration.rb', line 33

def not_rfc_mx_lookup_flow
  @not_rfc_mx_lookup_flow
end

#smtp_fail_fastObject

Returns the value of attribute smtp_fail_fast.



33
34
35
# File 'lib/truemail/configuration.rb', line 33

def smtp_fail_fast
  @smtp_fail_fast
end

#smtp_safe_checkObject

Returns the value of attribute smtp_safe_check.



33
34
35
# File 'lib/truemail/configuration.rb', line 33

def smtp_safe_check
  @smtp_safe_check
end

#whitelist_validationObject

Returns the value of attribute whitelist_validation.



33
34
35
# File 'lib/truemail/configuration.rb', line 33

def whitelist_validation
  @whitelist_validation
end

Instance Method Details

#argument_consistent?(method, argument) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
66
67
68
69
# File 'lib/truemail/configuration.rb', line 63

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?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/truemail/configuration.rb', line 89

def complete?
  !!verifier_email
end

#default_validation_type=(argument) ⇒ Object



53
54
55
56
# File 'lib/truemail/configuration.rb', line 53

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) ⇒ Object



78
79
80
81
82
83
84
85
86
87
# File 'lib/truemail/configuration.rb', line 78

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) ⇒ Object



58
59
60
61
# File 'lib/truemail/configuration.rb', line 58

def validation_type_for=(settings)
  validate_validation_type(settings)
  validation_type_by_domain.merge!(settings)
end

#verifier_domain=(domain) ⇒ Object



48
49
50
51
# File 'lib/truemail/configuration.rb', line 48

def verifier_domain=(domain)
  validate_arguments(domain, __method__)
  @verifier_domain = domain.downcase
end

#verifier_email=(email) ⇒ Object



42
43
44
45
46
# File 'lib/truemail/configuration.rb', line 42

def verifier_email=(email)
  validate_arguments(email, __method__)
  @verifier_email = email.downcase
  default_verifier_domain
end