Class: Solr::Response::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/solr/response/base.rb

Overview

The ASF licenses this file to You under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Direct Known Subclasses

Ruby, Xml

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_response) ⇒ Base

Returns a new instance of Base.



16
17
18
# File 'lib/solr/response/base.rb', line 16

def initialize(raw_response)
  @raw_response = raw_response
end

Instance Attribute Details

#raw_responseObject (readonly)

Returns the value of attribute raw_response.



14
15
16
# File 'lib/solr/response/base.rb', line 14

def raw_response
  @raw_response
end

Class Method Details

.make_response(request, raw) ⇒ Object

factory method for creating a Solr::Response::* from a request and the raw response content



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/solr/response/base.rb', line 22

def self.make_response(request, raw)

  # make sure response format seems sane
  unless [:xml, :ruby].include?(request.response_format)
    raise Solr::Exception.new("unknown response format: #{request.response_format}" )
  end

  # TODO: Factor out this case... perhaps the request object should provide the response class instead?  Or dynamically align by class name?
  #       Maybe the request itself could have the response handling features that get mixed in with a single general purpose response object?
  
  begin
    klass = eval(request.class.name.sub(/Request/,'Response'))
  rescue NameError
    raise Solr::Exception.new("unknown request type: #{request.class}")
  else
    klass.new(raw)
  end
  
end