Class: Orchestrate::RefList

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

Overview

An enumerator over a query for listing Ref values in an Orchestrate::KeyValue.

Defined Under Namespace

Classes: Fetcher

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key_value) ⇒ RefList

Instantiates a new RefList

Parameters:

  • key_value (KeyValue)

    The KeyValue item to retrieve Refs for.



26
27
28
# File 'lib/orchestrate/refs.rb', line 26

def initialize(key_value)
  @key_value = key_value
end

Instance Attribute Details

#key_valueKeyValue

Returns:



22
23
24
# File 'lib/orchestrate/refs.rb', line 22

def key_value
  @key_value
end

Instance Method Details

#[](ref_id) ⇒ Object

Accessor for individual Refs.

Parameters:

  • ref_id (#to_s)

    The ref of the specific immutable value to retrieve.



32
33
34
35
# File 'lib/orchestrate/refs.rb', line 32

def [](ref_id)
  response = @key_value.perform(:get, ref_id)
  Ref.new(@key_value.collection, @key_value.key, response)
end

#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_ids = kv.refs.take(20).map(&:ref)

Overloads:

  • #eachObject

    Returns Enumerator.

    Returns:

    • Enumerator

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

    Yield Parameters:

    • ref (Ref)

      the Ref item

See Also:



50
51
52
# File 'lib/orchestrate/refs.rb', line 50

def each(&block)
  Fetcher.new(self).each(&block)
end

#lazyEnumerator::Lazy

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

Returns:

  • (Enumerator::Lazy)


57
58
59
# File 'lib/orchestrate/refs.rb', line 57

def lazy
  Fetcher.new(self).lazy
end

#offset(count) ⇒ RefList::Fetcher

Set 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.

Returns:



73
74
75
# File 'lib/orchestrate/refs.rb', line 73

def offset(count)
  Fetcher.new(self).offset(count)
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.

Returns:



65
66
67
# File 'lib/orchestrate/refs.rb', line 65

def take(count)
  Fetcher.new(self).take(count)
end

#with_valuesRefList::Fetcher

Specifies that the query to Orchestrate should use the values parameter, and that the query should return the values for each ref.

Returns:



80
81
82
# File 'lib/orchestrate/refs.rb', line 80

def with_values
  Fetcher.new(self).with_values
end