Class: Nondisposable::Configuration
- Inherits:
-
Object
- Object
- Nondisposable::Configuration
- Defined in:
- lib/nondisposable.rb
Constant Summary collapse
- ON_CHECK_FAILURE_MODES =
[:allow, :reject].freeze
Instance Attribute Summary collapse
-
#additional_domains ⇒ Object
Returns the value of attribute additional_domains.
-
#additional_email_providers ⇒ Object
Providers to add to the bundled list — your own domain, a regional provider we missed.
-
#additional_tlds ⇒ Object
Your escape hatch from a stale snapshot.
-
#allowed_tlds ⇒ Object
Allowlist mode: when set, ONLY these TLDs are accepted and every other one is refused.
-
#blocked_tld_error_message ⇒ Object
---- Error messages -----------------------------------------------------.
-
#blocked_tlds ⇒ Object
TLDs to refuse even though they are perfectly real.
-
#check_parent_domains ⇒ Object
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).
-
#check_tld ⇒ Object
OFF by default, and it stays off: upgrading a gem must never silently start rejecting addresses that were fine yesterday.
-
#error_message ⇒ Object
Returns the value of attribute error_message.
-
#excluded_domains ⇒ Object
Returns the value of attribute excluded_domains.
-
#invalid_tld_error_message ⇒ Object
---- Error messages -----------------------------------------------------.
-
#lookalike_distance ⇒ Object
How many edits still count as "a typo".
-
#lookalike_error_message ⇒ Object
%suggestion is replaced with the full corrected address.
-
#on_check_failure ⇒ Object
Returns the value of attribute on_check_failure.
-
#reject_lookalike_domains ⇒ Object
Reject addresses one edit away from a well-known provider —
gmail.co,gmial.com,hotmial.com— with a message naming the correction.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize ⇒ Configuration
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_domains ⇒ Object
Returns the value of attribute additional_domains.
62 63 64 |
# File 'lib/nondisposable.rb', line 62 def additional_domains @additional_domains end |
#additional_email_providers ⇒ Object
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_tlds ⇒ Object
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_tlds ⇒ Object
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_message ⇒ Object
---- Error messages -----------------------------------------------------
118 119 120 |
# File 'lib/nondisposable.rb', line 118 def @blocked_tld_error_message end |
#blocked_tlds ⇒ Object
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_domains ⇒ Object
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_tld ⇒ Object
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_message ⇒ Object
Returns the value of attribute error_message.
62 63 64 |
# File 'lib/nondisposable.rb', line 62 def @error_message end |
#excluded_domains ⇒ Object
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_message ⇒ Object
---- Error messages -----------------------------------------------------
118 119 120 |
# File 'lib/nondisposable.rb', line 118 def @invalid_tld_error_message end |
#lookalike_distance ⇒ Object
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_message ⇒ Object
%suggestion is replaced with the full corrected address.
120 121 122 |
# File 'lib/nondisposable.rb', line 120 def @lookalike_error_message end |
#on_check_failure ⇒ Object
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_domains ⇒ Object
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 |