Class: Orchestrate::RefList::Fetcher
- Inherits:
-
Object
- Object
- Orchestrate::RefList::Fetcher
- Includes:
- Enumerable
- Defined in:
- lib/orchestrate/refs.rb
Overview
Responsible for actually retrieving the list of Refs from Orchestrate.
Instance Attribute Summary collapse
-
#key_value ⇒ KeyValue
The KeyValue to retrieve Refs for.
-
#limit ⇒ Integer
The maximum number of Refs to return.
-
#values ⇒ nil, true
Whether to request values for each Ref or not.
Ref Enumeration collapse
-
#each ⇒ Object
Iterates over each Ref for the KeyValue.
-
#lazy ⇒ Enumerator::Lazy
Creates a Lazy Enumerator for the Fetcher.
-
#offset(count = nil) ⇒ Object
Sets the offset for the query to Orchestrate, so you can skip items.
-
#take(count) ⇒ Array<Ref>
Returns the first n items.
-
#with_values ⇒ self
Specifies the query to Orchestrate shoul duse the
values
parameter, and the query should return values for each ref.
Instance Method Summary collapse
-
#initialize(reflist) ⇒ Fetcher
constructor
Instantiates a new RefList::Fetcher.
Constructor Details
#initialize(reflist) ⇒ Fetcher
Instantiates a new RefList::Fetcher.
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_value ⇒ KeyValue
The KeyValue to retrieve Refs for.
91 92 93 |
# File 'lib/orchestrate/refs.rb', line 91 def key_value @key_value end |
#limit ⇒ Integer
The maximum number of Refs to return.
95 96 97 |
# File 'lib/orchestrate/refs.rb', line 95 def limit @limit end |
#values ⇒ nil, true
Whether to request values for each Ref or not.
99 100 101 |
# File 'lib/orchestrate/refs.rb', line 99 def values @values end |
Instance Method Details
#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.
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 |
#lazy ⇒ Enumerator::Lazy
Creates a Lazy Enumerator for the Fetcher. If called inside the Application's
#in_parallel
block, pre-fetches the first page of results.
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 |
#offset ⇒ Integer #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.
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.
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_values ⇒ self
Specifies the query to Orchestrate shoul duse the values
parameter,
and the query should return values for each ref.
178 179 180 181 |
# File 'lib/orchestrate/refs.rb', line 178 def with_values @values = true self end |