Class: CursorResponseCollection

Inherits:
ResponseCollection show all
Defined in:
lib/bright/cursor_response_collection.rb

Constant Summary

Constants inherited from ResponseCollection

ResponseCollection::DEFAULT_NO_THREADS

Instance Attribute Summary collapse

Attributes inherited from ResponseCollection

#load_more_call, #paged_objects, #per_page

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ CursorResponseCollection

Returns a new instance of CursorResponseCollection.



5
6
7
8
9
10
# File 'lib/bright/cursor_response_collection.rb', line 5

def initialize(options = {})
  @collected_objects = [options[:seed_page]].flatten
  @per_page = options[:per_page].to_i
  @load_more_call = options[:load_more_call]
  @next_cursor = options[:next_cursor]
end

Instance Attribute Details

#collected_objectsObject

Returns the value of attribute collected_objects.



3
4
5
# File 'lib/bright/cursor_response_collection.rb', line 3

def collected_objects
  @collected_objects
end

Instance Method Details

#eachObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/bright/cursor_response_collection.rb', line 12

def each
  while (!@next_cursor.blank?) do
    objects_hsh = load_more_call.call(@next_cursor)
    objects = objects_hsh[:objects]
    @next_cursor = objects_hsh[:next_cursor]
    objects.each do |obj|
      yield obj
    end
    @collected_objects += objects
  end
end

#empty?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/bright/cursor_response_collection.rb', line 41

def empty?
  self.to_a.empty?
end

#lastObject



24
25
26
27
# File 'lib/bright/cursor_response_collection.rb', line 24

def last
  self.to_a
  return @collected_objects.last
end

#loaded_resultsObject



29
30
31
# File 'lib/bright/cursor_response_collection.rb', line 29

def loaded_results
  @collected_objects.flatten
end

#totalObject Also known as: size, length



33
34
35
36
# File 'lib/bright/cursor_response_collection.rb', line 33

def total
  self.to_a
  self.loaded_results.size
end