14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/moderate/word_list.rb', line 14
def load
cache_path = cache_file_path
begin
if File.exist?(cache_path)
if cache_valid?(cache_path)
words = File.read(cache_path, encoding: 'UTF-8').split("\n").to_set
return words unless words.empty?
else
logger.info("[moderate gem] Cache expired (older than #{CACHE_TTL / 86400} days). Refreshing word list...")
return download_and_cache(cache_path)
end
end
logger.info("[moderate gem] No cache found. Downloading word list for the first time...")
download_and_cache(cache_path)
rescue StandardError => e
logger.error("[moderate gem] Error loading word list: #{e.message}")
logger.debug("[moderate gem] #{e.backtrace.join("\n")}")
raise Moderate::Error, "Failed to load bad words list: #{e.message}"
end
end
|