Class: Cursor
Overview
Cursor
Used for paginating requests to the OneLogin API
Returns an enumerable object
Instance Method Summary collapse
- #each(start = 0) ⇒ Object
-
#initialize(url, options = {}) ⇒ Cursor
constructor
Create a new instance of the Cursor.
Constructor Details
#initialize(url, options = {}) ⇒ Cursor
Create a new instance of the Cursor.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/onelogin/api/cursor.rb', line 14 def initialize(url, = {}) @url = url @options = @model = [:model] @headers = [:headers] || {} @params = [:params] || {} @max_results = [:max_results] @collection = [] @after_cursor = .fetch(:after_cursor, nil) end |
Instance Method Details
#each(start = 0) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/onelogin/api/cursor.rb', line 27 def each(start = 0) return to_enum(:each, start) unless block_given? Array(@collection[start..-1]).each do |item| if @model yield(@model.new(item)) else yield(item) end end unless last? start = [@collection.size, start].max fetch_next_page each(start, &Proc.new) end end |