Module: RSolr::Response

Included in:
HashWithResponse
Defined in:
lib/rsolr/response.rb

Defined Under Namespace

Classes: PaginatedDocSet

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
6
7
8
# File 'lib/rsolr/response.rb', line 3

def self.included(base)
  unless base < Hash
    raise ArgumentError, "RSolr::Response expects to included only in (sub)classes of Hash; got included in '#{base}' instead."
  end
  base.send(:attr_reader, :request, :response)
end

Instance Method Details

#initialize_rsolr_response(request, response, result) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rsolr/response.rb', line 10

def initialize_rsolr_response(request, response, result)
  @request = request
  @response = response
  self.merge!(result)
  if self["response"] && self["response"]["docs"].is_a?(::Array)
    docs = PaginatedDocSet.new(self["response"]["docs"])
    docs.per_page = request[:params]["rows"]
    docs.page_start = request[:params]["start"]
    docs.page_total = self["response"]["numFound"].to_s.to_i
    self["response"]["docs"] = docs
  end
end

#with_indifferent_accessObject



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

def with_indifferent_access
  if defined?(::RSolr::HashWithIndifferentAccessWithResponse)
    ::RSolr::HashWithIndifferentAccessWithResponse.new(request, response, self)
  else
    if defined?(ActiveSupport::HashWithIndifferentAccess)
      RSolr.const_set("HashWithIndifferentAccessWithResponse", Class.new(ActiveSupport::HashWithIndifferentAccess))
      RSolr::HashWithIndifferentAccessWithResponse.class_eval <<-eos
        include RSolr::Response
        def initialize(request, response, result)
          super()
          initialize_rsolr_response(request, response, result)
        end
      eos
      ::RSolr::HashWithIndifferentAccessWithResponse.new(request, response, self)
    else
      raise RuntimeError, "HashWithIndifferentAccess is not currently defined"
    end
  end
end