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.



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

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.



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

def collected_objects
  @collected_objects
end

Instance Method Details

#eachObject



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

def each
  until @next_cursor.blank?
    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)


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

def empty?
  to_a.empty?
end

#lastObject



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

def last
  to_a
  @collected_objects.last
end

#loaded_resultsObject



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

def loaded_results
  @collected_objects.flatten
end

#totalObject Also known as: size, length



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

def total
  to_a
  loaded_results.size
end