Class: RiakJson::QueryResult

Inherits:
Object
  • Object
show all
Defined in:
lib/riak_json/query_result.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ QueryResult

Returns a new instance of QueryResult.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# 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

Instance Attribute Details

#documentsObject (readonly)

Returns the value of attribute documents.



25
26
27
# File 'lib/riak_json/query_result.rb', line 25

def documents
  @documents
end

#num_pagesObject (readonly)

Returns the value of attribute num_pages.



26
27
28
# File 'lib/riak_json/query_result.rb', line 26

def num_pages
  @num_pages
end

#pageObject (readonly)

Returns the value of attribute page.



27
28
29
# File 'lib/riak_json/query_result.rb', line 27

def page
  @page
end

#per_pageObject (readonly)

Returns the value of attribute per_page.



28
29
30
# File 'lib/riak_json/query_result.rb', line 28

def per_page
  @per_page
end

#totalObject (readonly)

Returns the value of attribute total.



29
30
31
# File 'lib/riak_json/query_result.rb', line 29

def total
  @total
end