Module: Nondisposable

Defined in:
lib/nondisposable.rb,
lib/nondisposable/tld.rb,
lib/nondisposable/engine.rb,
lib/nondisposable/version.rb,
lib/nondisposable/suggestion.rb,
lib/nondisposable/tld_list_updater.rb,
lib/nondisposable/domain_list_updater.rb,
app/models/nondisposable/disposable_domain.rb,
lib/generators/nondisposable/install_generator.rb,
sig/nondisposable.rbs

Defined Under Namespace

Modules: Generators, Suggestion, Tld Classes: Configuration, DisposableDomain, DomainListUpdater, Engine, Error, TldListUpdater

Constant Summary collapse

VERSION =

Returns:

  • (String)
"0.4.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

Lazily initialized so the gem works safely even when the host app never runs an initializer (previously a nil configuration made every check raise, which the validator surfaced as a validation error on all emails).



20
21
22
# File 'lib/nondisposable.rb', line 20

def configuration
  @configuration ||= Configuration.new
end

Class Method Details

.configure {|configuration| ... } ⇒ Object

Yields:



25
26
27
# File 'lib/nondisposable.rb', line 25

def self.configure
  yield(configuration)
end

.disposable?(email) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
# File 'lib/nondisposable.rb', line 29

def self.disposable?(email)
  return false if email.nil? || !email.include?('@')
  domain = email.to_s.split('@').last
  return false if domain.nil? || domain.empty?
  DisposableDomain.disposable?(domain.downcase)
end

.suggestion_for(email) ⇒ Object

"someone@gmial.com" => "someone@gmail.com", or nil when we have nothing useful to say. Never blocks anything by itself — hand it to a user and let them decide. See Nondisposable::Suggestion for how it decides.



55
56
57
# File 'lib/nondisposable.rb', line 55

def self.suggestion_for(email)
  Suggestion.for(email)
end

.valid_tld?(email) ⇒ Boolean

Does this address end in a TLD that actually exists?

A different question from #disposable?, catching a different kind of bad address: user@gmail.con is not a throwaway, it is a typo that produces an account nobody can ever reach. Answers true for anything we cannot judge — no domain, no dot, an IP literal — so it is safe to call on any input; pair it with a format validation if you also care about shape.

Returns:

  • (Boolean)


43
44
45
46
47
48
49
50
# File 'lib/nondisposable.rb', line 43

def self.valid_tld?(email)
  return true unless Tld.judgeable?(email)

  tld = Tld.extract(email)
  return false if tld.nil? # A domain with no TLD can't end in a real one

  Tld.valid?(tld) && !Tld.blocked?(tld)
end