Class: Orchestrate::RefList::Fetcher

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/orchestrate/refs.rb

Overview

Responsible for actually retrieving the list of Refs from Orchestrate.

Instance Attribute Summary collapse

Ref Enumeration collapse

Instance Method Summary collapse

Constructor Details

#initialize(reflist) ⇒ Fetcher

Instantiates a new RefList::Fetcher.

Parameters:

  • reflist (RefList)

    The RefList to base the queries on.



103
104
105
106
# File 'lib/orchestrate/refs.rb', line 103

def initialize(reflist)
  @key_value = reflist.key_value
  @limit = 100
end

Instance Attribute Details

#key_valueKeyValue

The KeyValue to retrieve Refs for.

Returns:



91
92
93
# File 'lib/orchestrate/refs.rb', line 91

def key_value
  @key_value
end

#limitInteger

The maximum number of Refs to return.

Returns:

  • (Integer)


95
96
97
# File 'lib/orchestrate/refs.rb', line 95

def limit
  @limit
end

#valuesnil, true

Whether to request values for each Ref or not.

Returns:

  • (nil, true)

    defaults to nil



99
100
101
# File 'lib/orchestrate/refs.rb', line 99

def values
  @values
end

Instance Method Details

#eachObject #each {|ref| ... } ⇒ Object

Iterates over each Ref for the KeyValue. Used as the basis for Enumerable. Refs are provided in time-series order, newest to oldest.

Examples:

ref_enum = kv.refs.each

Overloads:

  • #eachObject

    Returns Enumerator.

    Returns:

    • Enumerator

  • #each {|ref| ... } ⇒ Object

    Yield Parameters:

    • ref (Ref)

      the Ref item

Raises:



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# 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

#lazyEnumerator::Lazy

Creates a Lazy Enumerator for the Fetcher. If called inside the Application's #in_parallel block, pre-fetches the first page of results.

Returns:

  • (Enumerator::Lazy)


140
141
142
143
# File 'lib/orchestrate/refs.rb', line 140

def lazy
  return each.lazy if key_value.collection.app.inside_parallel?
  super
end

#offsetInteger #offset(count) ⇒ self

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.

Overloads:

  • #offsetInteger

    Returns the current offset value.

    Returns:

    • (Integer)

      the current offset value

  • #offset(count) ⇒ self

    Parameters:

    • count (Integer)

      The number of records to skip. Constrained to positive integers.

    Returns:

    • (self)


165
166
167
168
169
170
171
172
173
# 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) ⇒ Array<Ref>

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.

Parameters:

  • count (Integer)

    A positive integer constrained between 1 and 100.

Returns:



150
151
152
153
154
155
# 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_valuesself

Specifies the query to Orchestrate shoul duse the values parameter, and the query should return values for each ref.

Returns:

  • (self)


178
179
180
181
# File 'lib/orchestrate/refs.rb', line 178

def with_values
  @values = true
  self
end