Class: ProxyFetcher::ProvidersRegistry
- Inherits:
-
Object
- Object
- ProxyFetcher::ProvidersRegistry
- Defined in:
- lib/proxy_fetcher/configuration/providers_registry.rb
Overview
ProxyFetcher providers registry that stores all registered proxy providers.
Instance Method Summary collapse
-
#class_for(provider_name) ⇒ Class
Returns a class for specific provider if it is registered in the registry.
-
#providers ⇒ Hash
Returns providers hash where key is the name of the provider and value is an associated class.
-
#register(name, klass) ⇒ Object
Add custom provider to common registry.
Instance Method Details
#class_for(provider_name) ⇒ Class
Returns a class for specific provider if it is registered in the registry. Otherwise throws an exception.
47 48 49 50 51 52 53 |
# File 'lib/proxy_fetcher/configuration/providers_registry.rb', line 47 def class_for(provider_name) provider_name = provider_name.to_sym providers.fetch(provider_name) rescue KeyError raise ProxyFetcher::Exceptions::UnknownProvider, provider_name end |
#providers ⇒ Hash
Returns providers hash where key is the name of the provider and value is an associated class.
12 13 14 |
# File 'lib/proxy_fetcher/configuration/providers_registry.rb', line 12 def providers @providers ||= {} end |
#register(name, klass) ⇒ Object
Add custom provider to common registry. Requires proxy provider name (‘xroxy’ for example) and a class that implements the parsing logic.
29 30 31 32 33 |
# File 'lib/proxy_fetcher/configuration/providers_registry.rb', line 29 def register(name, klass) raise ProxyFetcher::Exceptions::RegisteredProvider, name if providers.key?(name.to_sym) providers[name.to_sym] = klass end |