Class: Nondisposable::DomainListUpdater
- Inherits:
-
Object
- Object
- Nondisposable::DomainListUpdater
- Defined in:
- lib/nondisposable/domain_list_updater.rb
Constant Summary collapse
- LIST_URL =
'https://raw.githubusercontent.com/disposable-email-domains/disposable-email-domains/master/disposable_email_blocklist.conf'- BUNDLED_LIST_PATH =
Snapshot of the upstream blocklist vendored into the gem, used to seed fresh installs so they are protected before the first remote update.
File.('../../data/disposable_email_blocklist.conf', __dir__)
- OPEN_TIMEOUT =
Network timeouts (seconds). Without these, a hung connection would block the calling job/thread indefinitely (Net::HTTP defaults to 60s open / 60s read).
10- READ_TIMEOUT =
10
Class Method Summary collapse
-
.seed ⇒ Object
Seeds the domain table from the blocklist snapshot bundled with the gem, but ONLY when the table is empty.
- .update ⇒ Object
Class Method Details
.seed ⇒ Object
Seeds the domain table from the blocklist snapshot bundled with the gem, but ONLY when the table is empty. This closes the fresh-install fail-open window where every email passed validation until the first successful remote update. Returns true if it seeded, false otherwise.
The bundled list is a snapshot from the gem's release date — always run DomainListUpdater.update (e.g. via the provided job) to stay current.
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/nondisposable/domain_list_updater.rb', line 57 def self.seed return false unless Nondisposable::DisposableDomain.none? Rails.logger.info "[nondisposable] Domain table is empty; seeding from the blocklist bundled with the gem..." count = replace_domains(bundled_domains) Rails.logger.info "[nondisposable] Seeded #{count} disposable domains from the bundled snapshot. Run Nondisposable::DomainListUpdater.update to fetch the latest list." true rescue StandardError => e Rails.logger.error "[nondisposable] Could not seed from the bundled list: #{e.}" false end |
.update ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/nondisposable/domain_list_updater.rb', line 20 def self.update Rails.logger.info "[nondisposable] Refreshing list of disposable domains..." begin response = fetch_list if response.is_a?(Net::HTTPSuccess) downloaded_domains = response.body.split("\n") raise "The list is empty. This might indicate a problem with the format." if downloaded_domains.empty? Rails.logger.info "[nondisposable] Downloaded list of disposable domains..." replace_domains(downloaded_domains) true else Rails.logger.error "[nondisposable] Failed to download the list. HTTP Status: #{response.code}" seed false end rescue SocketError => e Rails.logger.error "[nondisposable] Network error occurred: #{e.}" seed false rescue StandardError => e Rails.logger.error "[nondisposable] An error occurred when trying to update the list of disposable domains: #{e.}" seed false end end |