Class: Algolia::ObjectIterator

Inherits:
BaseIterator show all
Defined in:
lib/algolia/iterators/object_iterator.rb

Instance Attribute Summary

Attributes inherited from BaseIterator

#index_name, #opts, #transporter

Instance Method Summary collapse

Methods inherited from BaseIterator

#initialize

Methods included from Helpers

#check_array, #check_object, #chunk, #deserialize_settings, #get_object_id, #get_option, #handle_params, #hash_includes_subset?, included, #json_to_hash, #path_encode, #symbolize_hash, #to_json, #to_query_string

Constructor Details

This class inherits a constructor from Algolia::BaseIterator

Instance Method Details

#eachObject

Custom each function to iterate through the objects



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/algolia/iterators/object_iterator.rb', line 5

def each
  loop do
    data = {}

    if @response
      parsed_response = symbolize_hash(@response)
      if parsed_response[:hits].length
        parsed_response[:hits].each do |hit|
          yield hit
        end

        if parsed_response[:cursor].nil?
          @response = nil
          raise StopIteration
        else
          data[:cursor] = parsed_response[:cursor]
        end
      end
    end
    @response = @transporter.read(:POST, path_encode('1/indexes/%s/browse', @index_name), data, @opts)
  end
end