Sha256: 16c34dd4c8a302fa3fc11ebbffb80de8a969305f158b311609286e787d6f2a29

Contents?: true

Size: 1.22 KB

Versions: 2

Compression:

Stored size: 1.22 KB

Contents

module RSolr::Ext::Response
  
  autoload :Docs, 'rsolr-ext/response/docs'
  autoload :Facets, 'rsolr-ext/response/facets'
  autoload :Spelling, 'rsolr-ext/response/spelling'
  
  class Base < Mash
    
    attr :original_hash
    attr_reader :request_path, :request_params
    
    def initialize hash, handler, request_params
      super hash
      @original_hash = hash
      @request_path, @request_params = request_path, request_params
      extend Response
      extend Docs
      extend Facets
      extend Spelling
    end
    
    def header
      self['responseHeader']
    end
    
    def rows
      params[:rows].to_i
    end
    
    def params
      (header and header['params']) ? header['params'] : request_params
    end
    
    def ok?
      (header and header['status']) ? header['status'] == 0 : nil
    end
    
    def method_missing *args, &blk
      self.original_hash.send *args, &blk
    end
    
  end
  
  module Response
    
    def response
      self[:response]
    end
    
    # short cut to response['numFound']
    def total
      response[:numFound].to_s.to_i
    end
    
    def total
      response[:numFound].to_s.to_i
    end
    
    def start
      response[:start].to_s.to_i
    end
    
  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rsolr-ext-1.0.0 lib/rsolr-ext/response.rb
rsolr-ext-0.12.1 lib/rsolr-ext/response.rb