Class: Orchestrate::Graph::RelationStem::Traversal
- Inherits:
-
Object
- Object
- Orchestrate::Graph::RelationStem::Traversal
- Includes:
- Enumerable
- Defined in:
- lib/orchestrate/graph.rb
Overview
Traverses from a single node in the graph across one or more edges. The workhorse for gathering results from a graph search.
Instance Attribute Summary collapse
-
#edges ⇒ Array<#to_s>
The graph types and depth to traverse.
-
#kv_item ⇒ KeyValue
The KeyValue item from which the graph query originates.
Instance Method Summary collapse
-
#[](edge) ⇒ Traversal
Add a new type to the depth of the graph query.
-
#each(&block) ⇒ Object
Retrieves the related items, and iterates over each item in the result.
-
#initialize(kv_item, edge_names) ⇒ Traversal
constructor
Instantiates a new Traversal.
Constructor Details
#initialize(kv_item, edge_names) ⇒ Traversal
Instantiates a new Traversal.
120 121 122 123 |
# File 'lib/orchestrate/graph.rb', line 120 def initialize(kv_item, edge_names) @kv_item = kv_item @edges = edge_names end |
Instance Attribute Details
#edges ⇒ Array<#to_s>
The graph types and depth to traverse.
115 116 117 |
# File 'lib/orchestrate/graph.rb', line 115 def edges @edges end |
#kv_item ⇒ KeyValue
The KeyValue item from which the graph query originates.
111 112 113 |
# File 'lib/orchestrate/graph.rb', line 111 def kv_item @kv_item end |
Instance Method Details
#[](edge) ⇒ Traversal
Add a new type to the depth of the graph query.
128 129 130 |
# File 'lib/orchestrate/graph.rb', line 128 def [](edge) self.class.new(kv_item, [edges, edge].flatten) end |
#each(&block) ⇒ Object
Retrieves the related items, and iterates over each item in the result. Used as the basis for Enumerable methods.
137 138 139 140 141 142 143 144 145 146 |
# File 'lib/orchestrate/graph.rb', line 137 def each(&block) @response ||= kv_item.perform(:get_relations, *edges) return enum_for(:each) unless block raise ResultsNotReady if kv_item.collection.app.inside_parallel? @response.results.each do |listing| listing_collection = kv_item.collection.app[listing['path']['collection']] yield KeyValue.from_listing(listing_collection, listing, @response) end @response = nil end |