Method: NoSE::QueryGraph::Graph.from_path

Defined in:
lib/nose/query_graph.rb

.from_path(path) ⇒ Graph

Construct a graph from a KeyPath

Returns:



323
324
325
326
327
328
329
330
331
332
333
334
335
336
# File 'lib/nose/query_graph.rb', line 323

def self.from_path(path)
  return Graph.new if path.empty?

  path = path.entries if path.is_a?(KeyPath)
  graph = Graph.new
  prev_node = graph.add_node path.first.parent
  path[1..-1].each do |key|
    next_node = graph.add_node key.entity
    graph.add_edge prev_node, next_node, key
    prev_node = next_node
  end

  graph
end