class Easywins::ListManager
Constants
- DOWNLOAD_URL
- LIST_LOCATION
Public Class Methods
file_exists?()
click to toggle source
# File lib/easywins/list_manager.rb, line 8 def self.file_exists? File.exists?(LIST_LOCATION) end
get_list()
click to toggle source
# File lib/easywins/list_manager.rb, line 20 def self.get_list sanitize_list(File.read(LIST_LOCATION)) end
update_file!()
click to toggle source
# File lib/easywins/list_manager.rb, line 12 def self.update_file! download = download_file! if download.code != 200 || download.body.size.zero? raise UpdateError.new("Unable to download list from #{DOWNLOAD_URL}") end write_to_file!(download.body) end
Private Class Methods
download_file!()
click to toggle source
# File lib/easywins/list_manager.rb, line 26 def self.download_file! http_client.do_get(DOWNLOAD_URL) end
http_client()
click to toggle source
# File lib/easywins/list_manager.rb, line 40 def self.http_client @http_client ||= Easywins::HttpClient.new end
sanitize_list(list)
click to toggle source
# File lib/easywins/list_manager.rb, line 36 def self.sanitize_list(list) list.split("\n").map { |l| l.strip }.delete_if { |l| l.empty? || !l.start_with?('/') } end
write_to_file!(content)
click to toggle source
# File lib/easywins/list_manager.rb, line 30 def self.write_to_file!(content) open(LIST_LOCATION, 'w') do |f| f.puts(sanitize_list(content).join("\n")) end end