class Orchestrate::RefList::Fetcher

Responsible for actually retrieving the list of Refs from Orchestrate.

Attributes

key_value[RW]

The KeyValue to retrieve Refs for. @return [KeyValue]

limit[RW]

The maximum number of Refs to return. @return [Integer]

values[RW]

Whether to request values for each Ref or not. @return [nil, true] defaults to nil

Public Class Methods

new(reflist) click to toggle source

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

each() { |from_listing| ... } click to toggle source

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
lazy() click to toggle source

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]

Calls superclass method
# File lib/orchestrate/refs.rb, line 140
def lazy
  return each.lazy if key_value.collection.app.inside_parallel?
  super
end
offset(count=nil) click to toggle source

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
take(count) click to toggle source

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>]

Calls superclass method
# 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
with_values() click to toggle source

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