Class: Orchestrate::RefList
- Inherits:
-
Object
- Object
- Orchestrate::RefList
- 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
-
#[](ref_id) ⇒ Object
Accessor for individual Refs.
-
#each(&block) ⇒ Object
Iterates over each Ref for the KeyValue.
-
#initialize(key_value) ⇒ RefList
constructor
Instantiates a new RefList.
-
#lazy ⇒ Enumerator::Lazy
Creates a Lazy Enumerator for the RefList.
-
#offset(count) ⇒ RefList::Fetcher
Set the offset for the query to Orchestrate, so you can skip items.
-
#take(count) ⇒ Array<Ref>
Returns the first n items.
-
#with_values ⇒ RefList::Fetcher
Specifies that the query to Orchestrate should use the
values
parameter, and that the query should return the values for each ref.
Constructor Details
#initialize(key_value) ⇒ RefList
Instantiates a new RefList
26 27 28 |
# File 'lib/orchestrate/refs.rb', line 26 def initialize(key_value) @key_value = key_value end |
Instance Attribute Details
#key_value ⇒ KeyValue
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.
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 |
#each ⇒ Object #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.
50 51 52 |
# File 'lib/orchestrate/refs.rb', line 50 def each(&block) Fetcher.new(self).each(&block) end |
#lazy ⇒ Enumerator::Lazy
Creates a Lazy Enumerator for the RefList. If called inside the Applciation's
#in_parallel
block, pre-fetches the first page of results.
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.
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.
65 66 67 |
# File 'lib/orchestrate/refs.rb', line 65 def take(count) Fetcher.new(self).take(count) end |
#with_values ⇒ RefList::Fetcher
Specifies that the query to Orchestrate should use the values
parameter,
and that the query should return the values for each ref.
80 81 82 |
# File 'lib/orchestrate/refs.rb', line 80 def with_values Fetcher.new(self).with_values end |