Class: Orchestrate::Graph::RelationStem::Traversal

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(kv_item, edge_names) ⇒ Traversal

Instantiates a new Traversal.

Parameters:

  • kv_item (KeyValue)

    The KeyValue item from which to traverse.

  • edge_names (Array<#to_s>)

    The graph types and depth to traverse.



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

#edgesArray<#to_s>

The graph types and depth to traverse.

Returns:

  • (Array<#to_s>)


115
116
117
# File 'lib/orchestrate/graph.rb', line 115

def edges
  @edges
end

#kv_itemKeyValue

The KeyValue item from which the graph query originates.

Returns:



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.

Parameters:

  • edge (#to_s)

    The type of relation to traverse.

Returns:



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.

Raises:



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