class Mallory::Backend::File

Public Class Methods

new(filename) click to toggle source

It would be cool to add signal trap to refresh proxy list when file contents change (with initial validation, so if file is malformed, old list stays)

# File lib/mallory/backend/file.rb, line 8
def initialize(filename)
  @proxies = []
  begin
    lines = ::File.readlines(filename)
    raise if lines.nil?
    raise if lines.empty?
  rescue
    raise("Proxy file missing or empty")
  end
  lines.each do |line|
    if line.strip.match(/.*:\d{2,6}/)
      @proxies << line.strip
    else raise("Wrong format") end
  end
end

Public Instance Methods

all() click to toggle source
# File lib/mallory/backend/file.rb, line 28
def all
  @proxies
end
any() click to toggle source
# File lib/mallory/backend/file.rb, line 24
def any
  @proxies.sample
end