class RiakJson::QueryResult

QueryResult is a helper object that holds the results of a collection.find_all query

Attributes

documents[R]
num_pages[R]
page[R]
per_page[R]
total[R]

Public Class Methods

new(response) click to toggle source
# File lib/riak_json/query_result.rb, line 31
def initialize(response)
  if response.nil? or response.empty?
    result_hash = {}
  else
    result_hash = JSON.parse(response)
    if result_hash.kind_of? Array and result_hash.empty?
      result_hash = {}
    end
  end
  
  @num_pages = result_hash.fetch('num_pages', 0)
  @page = result_hash.fetch('page', 0)
  @total = result_hash.fetch('total', 0)
  @per_page = result_hash.fetch('per_page', 0)
  
  documents = result_hash.fetch('data', [])
  @documents = documents.map { | body | RiakJson::Document.new(body['_id'], body) }
end

Public Instance Methods

empty?() click to toggle source

Return true if no results came back for a query @return [Boolean]

# File lib/riak_json/query_result.rb, line 52
def empty?
  self.total == 0
end