Class: RSolr::HTTPClient::Connector
- Inherits:
-
Object
- Object
- RSolr::HTTPClient::Connector
- Defined in:
- lib/rsolr/http_client.rb
Instance Attribute Summary collapse
-
#adapter_name ⇒ Object
Returns the value of attribute adapter_name.
Instance Method Summary collapse
-
#connect(url) ⇒ Object
Creates and returns an instance of RSolr::HTTPClient::Adapter::* The “url” is a full/valid url.
-
#initialize(adapter_name = :curb) ⇒ Connector
constructor
A new instance of Connector.
Constructor Details
#initialize(adapter_name = :curb) ⇒ Connector
Returns a new instance of Connector.
34 35 36 |
# File 'lib/rsolr/http_client.rb', line 34 def initialize(adapter_name = :curb) @adapter_name = adapter_name end |
Instance Attribute Details
#adapter_name ⇒ Object
Returns the value of attribute adapter_name.
32 33 34 |
# File 'lib/rsolr/http_client.rb', line 32 def adapter_name @adapter_name end |
Instance Method Details
#connect(url) ⇒ Object
Creates and returns an instance of RSolr::HTTPClient::Adapter::* The “url” is a full/valid url. Example: connector = RSolr::HTTPClient::Connector.new client = connector.connect(‘google.com’)
TODO: this should be less verbose… something like RSolr:HTTPClient.connect(url, adapter=:curb)
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rsolr/http_client.rb', line 45 def connect(url) case adapter_name when :curb klass = 'Curb' when :net_http klass = 'NetHTTP' else raise UnkownAdapterError.new("Name: #{adapter_name}") end begin RSolr::HTTPClient::Base.new RSolr::HTTPClient::Adapter.const_get(klass).new(url) rescue ::URI::InvalidURIError raise "#{$!} == #{url}" end end |