class TempoIQ::Cursor
Cursor
is an abstraction over a sequence / stream of objects. It uses lazy iteration to transparently fetch segments of data from the server.
It implements the Enumerable interface, which means convenience functions such as Enumerable#to_a are available if you know you're working with a small enough segment of data that can reasonably fit in memory.
Constants
- NEXT_QUERY
- PAGE_LINK
Attributes
headers[R]
query[R]
remoter[R]
route[R]
segment_key[R]
Public Class Methods
new(klass, remoter, route, query, headers = {}, segment_key = "data")
click to toggle source
# File lib/tempoiq/models/cursor.rb, line 20 def initialize(klass, remoter, route, query, headers = {}, segment_key = "data") @klass = klass @remoter = remoter @route = route @query = query @headers = headers @segment_key = segment_key end
Public Instance Methods
each() { |from_hash| ... }
click to toggle source
# File lib/tempoiq/models/cursor.rb, line 29 def each segment = nil until segment == nil && query == nil do json = get_segment(JSON.dump(query.to_hash)) segment = json[segment_key] segment.each { |item| yield @klass.from_hash(item) } segment = nil @query = json.fetch(PAGE_LINK, {})[NEXT_QUERY] end end
Private Instance Methods
get_segment(next_query)
click to toggle source
# File lib/tempoiq/models/cursor.rb, line 42 def get_segment(next_query) remoter.get(route, next_query, headers).on_success do |result| JSON.parse(result.body) end end