Skip to content

Commit

Permalink
Don't allow to set blank values ad an adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
nbulaj committed Dec 5, 2017
1 parent 2f2b9b5 commit 2ebe4a5
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lib/proxy_fetcher/document/adapters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class Adapters

class << self
def lookup(name_or_class)
raise Exceptions::BlankAdapter if name_or_class.nil? || name_or_class.to_s.empty?

case name_or_class
when Symbol, String
adapter_name = name_or_class.to_s.capitalize << ADAPTER
Expand Down
10 changes: 10 additions & 0 deletions lib/proxy_fetcher/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ def initialize(name)
end
end

class BlankAdapter < Error
def initialize(*)
super(<<-MSG.strip.squeeze
you need to specify adapter for HTML parsing: ProxyFetcher.config.adapter = :nokogiri.
You can use one of the predefined adapters (:nokogiri or :oga) or your own implementation.
MSG
)
end
end

class AdapterSetupError < Error
def initialize(adapter_name, reason)
adapter = demodulize(adapter_name.remove('Adapter'))
Expand Down
2 changes: 0 additions & 2 deletions lib/proxy_fetcher/providers/http_tunnel.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'irb'

module ProxyFetcher
module Providers
class HTTPTunnel < Base
Expand Down
4 changes: 2 additions & 2 deletions proxy_fetcher.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ require 'proxy_fetcher/version'
Gem::Specification.new do |gem|
gem.name = 'proxy_fetcher'
gem.version = ProxyFetcher.gem_version
gem.date = '2017-11-13'
gem.date = '2017-12-05'
gem.summary = 'Ruby gem for dealing with proxy lists from different providers'
gem.description = 'This gem can help your Ruby application to make HTTP(S) requests ' \
'from proxy server by fetching and validating proxy lists from the different providers.'
'using proxies by fetching and validating proxy lists from the different providers.'
gem.authors = ['Nikita Bulai']
gem.email = '[email protected]'
gem.require_paths = ['lib']
Expand Down
5 changes: 5 additions & 0 deletions spec/proxy_fetcher/document/adapters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
expect(described_class.lookup(Struct)).to eq(Struct)
end

it 'raises an exception if passed value is blank' do
expect { described_class.lookup(nil) }.to raise_error(ProxyFetcher::Exceptions::BlankAdapter)
expect { described_class.lookup('') }.to raise_error(ProxyFetcher::Exceptions::BlankAdapter)
end

it "raises an exception if adapter doesn't exist" do
expect { described_class.lookup('wrong') }.to raise_error(ProxyFetcher::Exceptions::UnknownAdapter)
end
Expand Down

0 comments on commit 2ebe4a5

Please sign in to comment.