Class: Ork::ResultSet
- Inherits:
-
Object
- Object
- Ork::ResultSet
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/ork/result_set.rb
Class Method Summary collapse
-
.all(model, keys = nil) ⇒ Object
Find all documents in the Document’s bucket and return them.
Instance Method Summary collapse
-
#all ⇒ Object
Get the array of objects.
-
#has_next_page? ⇒ Boolean
Determine whether a SecondaryIndex fetch has a next page available.
-
#initialize(model, index, query, options = {}) ⇒ ResultSet
constructor
A new instance of ResultSet.
-
#inspect ⇒ Object
Pretty print for the ResultSet It uses keys when the objects are not present.
-
#keys(&block) ⇒ Object
Get the array of matched keys.
-
#next_page ⇒ Object
Get a new ResultSet fetch for the next page.
Constructor Details
#initialize(model, index, query, options = {}) ⇒ ResultSet
Returns a new instance of ResultSet.
11 12 13 14 |
# File 'lib/ork/result_set.rb', line 11 def initialize(model, index, query, ={}) @model, @index, @query, @options = model, index, query, @bucket = @model.bucket end |
Class Method Details
.all(model, keys = nil) ⇒ Object
Find all documents in the Document’s bucket and return them.
@return Ork::ResultSet<Document> all the documents in the bucket
@Note: This operation can be incredibly expensive and should not
be used in production applications.
22 23 24 25 26 |
# File 'lib/ork/result_set.rb', line 22 def self.all(model, keys = nil) new(model, nil, nil).tap do |r| r.instance_variable_set(:@keys, keys || model.bucket.keys) end end |
Instance Method Details
#all ⇒ Object
Get the array of objects
48 49 50 51 |
# File 'lib/ork/result_set.rb', line 48 def all return if self.keys.nil? @all ||= load_robjects @bucket.get_many(@keys) end |
#has_next_page? ⇒ Boolean
Determine whether a SecondaryIndex fetch has a next page available
66 67 68 |
# File 'lib/ork/result_set.rb', line 66 def has_next_page? keys.respond_to?(:continuation) && !!keys.continuation end |
#inspect ⇒ Object
Pretty print for the ResultSet It uses keys when the objects are not present.
31 32 33 34 35 |
# File 'lib/ork/result_set.rb', line 31 def inspect string = "#<#{self.class}:#{@options} %s>" string % (@all || self.keys).inspect end |
#keys(&block) ⇒ Object
Get the array of matched keys
39 40 41 42 43 44 |
# File 'lib/ork/result_set.rb', line 39 def keys(&block) @keys ||= @bucket.client.backend do |b| b.get_index @bucket, @index.riak_name, @query, @options, &block end end |
#next_page ⇒ Object
Get a new ResultSet fetch for the next page
55 56 57 58 59 60 61 62 |
# File 'lib/ork/result_set.rb', line 55 def next_page raise Ork::NoNextPage.new 'There is no next page' unless has_next_page? self.class.new(@model, @index, @query, @options.merge(continuation: keys.continuation)) end |