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_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.


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

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.


31
32
33
# File 'lib/truemail/configuration.rb', line 31

def not_rfc_mx_lookup_flow
  @not_rfc_mx_lookup_flow
end

#smtp_fail_fastObject

Returns the value of attribute smtp_fail_fast.


31
32
33
# File 'lib/truemail/configuration.rb', line 31

def smtp_fail_fast
  @smtp_fail_fast
end

#smtp_safe_checkObject

Returns the value of attribute smtp_safe_check.


31
32
33
# File 'lib/truemail/configuration.rb', line 31

def smtp_safe_check
  @smtp_safe_check
end

#whitelist_validationObject

Returns the value of attribute whitelist_validation.


31
32
33
# File 'lib/truemail/configuration.rb', line 31

def whitelist_validation
  @whitelist_validation
end

Instance Method Details

#argument_consistent?(method, argument) ⇒ Boolean

Returns:

  • (Boolean)

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

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)

87
88
89
# File 'lib/truemail/configuration.rb', line 87

def complete?
  !!verifier_email
end

#default_validation_type=(argument) ⇒ Object


51
52
53
54
# File 'lib/truemail/configuration.rb', line 51

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


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

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


56
57
58
59
# File 'lib/truemail/configuration.rb', line 56

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

#verifier_domain=(domain) ⇒ Object


46
47
48
49
# File 'lib/truemail/configuration.rb', line 46

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

#verifier_email=(email) ⇒ Object


40
41
42
43
44
# File 'lib/truemail/configuration.rb', line 40

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