Class: RiakJson::QueryResult
- Inherits:
-
Object
- Object
- RiakJson::QueryResult
- 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
-
#documents ⇒ Object
readonly
Returns the value of attribute documents.
-
#num_pages ⇒ Object
readonly
Returns the value of attribute num_pages.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#per_page ⇒ Object
readonly
Returns the value of attribute per_page.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Instance Method Summary collapse
-
#initialize(response) ⇒ QueryResult
constructor
A new instance of QueryResult.
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
#documents ⇒ Object (readonly)
Returns the value of attribute documents.
25 26 27 |
# File 'lib/riak_json/query_result.rb', line 25 def documents @documents end |
#num_pages ⇒ Object (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 |
#page ⇒ Object (readonly)
Returns the value of attribute page.
27 28 29 |
# File 'lib/riak_json/query_result.rb', line 27 def page @page end |
#per_page ⇒ Object (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 |
#total ⇒ Object (readonly)
Returns the value of attribute total.
29 30 31 |
# File 'lib/riak_json/query_result.rb', line 29 def total @total end |