Class: Nondisposable::Configuration

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

Constant Summary collapse

ON_CHECK_FAILURE_MODES =
[:allow, :reject].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/nondisposable.rb', line 122

def initialize
  @error_message = "provider is not allowed"
  @additional_domains = []
  @excluded_domains = []
  @on_check_failure = :allow
  @check_parent_domains = true

  @check_tld = false
  @additional_tlds = []
  @blocked_tlds = []
  @allowed_tlds = nil

  @reject_lookalike_domains = false
  @lookalike_distance = 1
  @additional_email_providers = []

  @invalid_tld_error_message = "doesn't look like a real email address"
  @blocked_tld_error_message = "domain ending is not allowed"
  @lookalike_error_message = "looks like a typo. Did you mean %{suggestion}?"
end

Instance Attribute Details

#additional_domainsObject

Returns the value of attribute additional_domains.



62
63
64
# File 'lib/nondisposable.rb', line 62

def additional_domains
  @additional_domains
end

#additional_email_providersObject

Providers to add to the bundled list — your own domain, a regional provider we missed. Adding one both makes it a suggestion candidate and, more importantly, stops its users being told they made a typo.



114
115
116
# File 'lib/nondisposable.rb', line 114

def additional_email_providers
  @additional_email_providers
end

#additional_tldsObject

Your escape hatch from a stale snapshot. A TLD delegated after this gem's release is unknown to the bundled list; naming it here accepts it immediately, with no release to wait for. Dots optional: "app" == ".app".



81
82
83
# File 'lib/nondisposable.rb', line 81

def additional_tlds
  @additional_tlds
end

#allowed_tldsObject

Allowlist mode: when set, ONLY these TLDs are accepted and every other one is refused. nil (the default) means "any TLD in the root zone". ⚠️ This is a blunt instrument — %w[es] turns away every customer who happens to use a .com address. Reach for blocked_tlds first.



92
93
94
# File 'lib/nondisposable.rb', line 92

def allowed_tlds
  @allowed_tlds
end

#blocked_tld_error_messageObject

---- Error messages -----------------------------------------------------



118
119
120
# File 'lib/nondisposable.rb', line 118

def blocked_tld_error_message
  @blocked_tld_error_message
end

#blocked_tldsObject

TLDs to refuse even though they are perfectly real. The usual reason is abuse economics rather than validity — the historically free Freenom set (%w[tk ml ga cf gq]) is the classic example.



86
87
88
# File 'lib/nondisposable.rb', line 86

def blocked_tlds
  @blocked_tlds
end

#check_parent_domainsObject

Whether to also match parent domains: with the default true, an email at x.tempmail.com is blocked when tempmail.com is on the list (checks up to DisposableDomain::PARENT_MATCH_DEPTH parent labels, never a bare TLD).



66
67
68
# File 'lib/nondisposable.rb', line 66

def check_parent_domains
  @check_parent_domains
end

#check_tldObject

OFF by default, and it stays off: upgrading a gem must never silently start rejecting addresses that were fine yesterday. Turn it on to reject addresses whose TLD is not in the IANA root zone — user@gmail.con and friends, which are typos rather than throwaways but produce an account nobody can ever reach.



76
77
78
# File 'lib/nondisposable.rb', line 76

def check_tld
  @check_tld
end

#error_messageObject

Returns the value of attribute error_message.



62
63
64
# File 'lib/nondisposable.rb', line 62

def error_message
  @error_message
end

#excluded_domainsObject

Returns the value of attribute excluded_domains.



62
63
64
# File 'lib/nondisposable.rb', line 62

def excluded_domains
  @excluded_domains
end

#invalid_tld_error_messageObject

---- Error messages -----------------------------------------------------



118
119
120
# File 'lib/nondisposable.rb', line 118

def invalid_tld_error_message
  @invalid_tld_error_message
end

#lookalike_distanceObject

How many edits still count as "a typo". 1 (the default) is the distance at which acting on a guess is safe; at 2, genuinely different domains start colliding with each other. 0 disables suggestions entirely.



109
110
111
# File 'lib/nondisposable.rb', line 109

def lookalike_distance
  @lookalike_distance
end

#lookalike_error_messageObject

%suggestion is replaced with the full corrected address.



120
121
122
# File 'lib/nondisposable.rb', line 120

def lookalike_error_message
  @lookalike_error_message
end

#on_check_failureObject

Returns the value of attribute on_check_failure.



67
68
69
# File 'lib/nondisposable.rb', line 67

def on_check_failure
  @on_check_failure
end

#reject_lookalike_domainsObject

Reject addresses one edit away from a well-known provider — gmail.co, gmial.com, hotmial.com — with a message naming the correction.

OFF by default and worth leaving off unless you have thought about it: a suggestion is a guess about intent, and a wrong guess here stops a real person signing up with their real address. Nondisposable.suggestion_for is always available and blocks nothing, which is the gentler way to use this: show the hint, let the human decide.



104
105
106
# File 'lib/nondisposable.rb', line 104

def reject_lookalike_domains
  @reject_lookalike_domains
end