Module: Georeferencer::CollectionIterator
- Defined in:
- lib/georeferencer/mixins/collection_iterator.rb
Overview
This is mixed into Her::Model::Relation and redefines how ‘fetch()` works, iterating over pages from the GR endpoint
Instance Method Summary collapse
Instance Method Details
#fetch ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/georeferencer/mixins/collection_iterator.rb', line 5 def fetch # only invoke this is the parent is a Georeferencer class if @parent.ancestors.include?(Georeferencer::Base) # get the collection @_collection = super = @_collection..except(:start) # check the params don't specifically include a :start argument (in which case we don't need to loop), # and that the response metadata includes a :start key if !start_included? && @_collection.[:start].present? && (!limited_included? || (limited_included? && @_collection.count < params[:limit])) @params.merge!(start: @_collection.[:start]) loop do clear_fetch_cache! new_collection = super @_collection += new_collection break if limited_included? && @_collection.count >= @params[:limit] if new_collection.[:start].present? && new_collection.[:start] != @params[:start] @params.merge!(start: new_collection.[:start]) else break end end end Her::Collection.new(@_collection, ) else super end end |
#limited_included? ⇒ Boolean
37 38 39 |
# File 'lib/georeferencer/mixins/collection_iterator.rb', line 37 def limited_included? (@params.keys.include?(:limit) || @params.keys.include?("limit")) end |
#start_included? ⇒ Boolean
41 42 43 |
# File 'lib/georeferencer/mixins/collection_iterator.rb', line 41 def start_included? (@params.keys.include?(:start) || @params.keys.include?("start")) end |