class Orchestrate::RefList::Fetcher
Responsible for actually retrieving the list of Refs from Orchestrate
.
Attributes
The KeyValue
to retrieve Refs for. @return [KeyValue]
The maximum number of Refs to return. @return [Integer]
Whether to request values for each Ref
or not. @return [nil, true] defaults to nil
Public Class Methods
Instantiates a new RefList::Fetcher
. @param reflist [RefList] The RefList
to base the queries on.
# File lib/orchestrate/refs.rb, line 103 def initialize(reflist) @key_value = reflist.key_value @limit = 100 end
Public Instance Methods
Iterates over each Ref
for the KeyValue
. Used as the basis for Enumerable. Refs are provided in time-series order, newest to oldest. @overload each
@return Enumerator
@overload each(&block)
@yieldparam [Ref] ref the Ref item
@example
ref_enum = kv.refs.each
# File lib/orchestrate/refs.rb, line 120 def each params = {limit: limit} params[:offset] = offset if offset params[:values] = true if values @response ||= key_value.perform(:list_refs, params) return enum_for(:each) unless block_given? raise ResultsNotReady.new if key_value.collection.app.inside_parallel? loop do @response.results.each do |doc| yield Ref.from_listing(key_value.collection, doc, @response) end break unless @response.next_link @response = @response.next_results end @response = nil end
Creates a Lazy Enumerator for the Fetcher
. If called inside the Application’s ‘#in_parallel` block, pre-fetches the first page of results. @return [Enumerator::Lazy]
# File lib/orchestrate/refs.rb, line 140 def lazy return each.lazy if key_value.collection.app.inside_parallel? super end
Sets the offset for the query to Orchestrate
, so you can skip items. Does not fetch results. Implemented as a separate method from drop, unlike take
, because take is a more common use case. @overload offset
@return [Integer] the current offset value
@overload offset(count)
@param count [Integer] The number of records to skip. Constrained to positive integers. @return [self]
# File lib/orchestrate/refs.rb, line 165 def offset(count=nil) if count count = 1 if count < 1 @offset = count.to_i return self else @offset end end
Returns the first n items. Equivalent to Enumerable#take. Sets the ‘limit` parameter on the query to Orchestrate
, so we don’t ask for more items than desired. @param count [Integer] A positive integer constrained between 1 and 100. @return [Array<Ref>]
# File lib/orchestrate/refs.rb, line 150 def take(count) count = 1 if count < 1 count = 100 if count > 100 @limit = count super(count) end
Specifies the query to Orchestrate
shoul duse the ‘values` parameter, and the query should return values for each ref. @return [self]
# File lib/orchestrate/refs.rb, line 178 def with_values @values = true self end