Class: Mallory::Backend::File
- Inherits:
-
Object
- Object
- Mallory::Backend::File
- Defined in:
- lib/mallory/backend/file.rb
Instance Method Summary collapse
- #all ⇒ Object
- #any ⇒ Object
-
#initialize(filename) ⇒ File
constructor
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).
Constructor Details
#initialize(filename) ⇒ File
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)
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# 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 |
Instance Method Details
#all ⇒ Object
28 29 30 |
# File 'lib/mallory/backend/file.rb', line 28 def all @proxies end |
#any ⇒ Object
24 25 26 |
# File 'lib/mallory/backend/file.rb', line 24 def any @proxies.sample end |