Class: ActiveGraph::Relationship::Persistence::QueryFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/active_graph/relationship/persistence/query_factory.rb

Overview

This class builds and executes a Cypher query, using information from the graph objects to determine

whether they need to be created simultaneously.
It keeps the rel instance from being responsible for inspecting the nodes or talking with Shared::QueryFactory.

Constant Summary collapse

NODE_SYMBOLS =
[:from_node, :to_node]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(from_node, to_node, rel) ⇒ QueryFactory

Returns a new instance of QueryFactory.



9
10
11
12
13
# File 'lib/active_graph/relationship/persistence/query_factory.rb', line 9

def initialize(from_node, to_node, rel)
  @from_node = from_node
  @to_node = to_node
  @rel = rel
end

Instance Attribute Details

#from_nodeObject (readonly)

Returns the value of attribute from_node.



7
8
9
# File 'lib/active_graph/relationship/persistence/query_factory.rb', line 7

def from_node
  @from_node
end

#relObject (readonly)

Returns the value of attribute rel.



7
8
9
# File 'lib/active_graph/relationship/persistence/query_factory.rb', line 7

def rel
  @rel
end

#to_nodeObject (readonly)

Returns the value of attribute to_node.



7
8
9
# File 'lib/active_graph/relationship/persistence/query_factory.rb', line 7

def to_node
  @to_node
end

#unwrapped_relObject (readonly)

Returns the value of attribute unwrapped_rel.



7
8
9
# File 'lib/active_graph/relationship/persistence/query_factory.rb', line 7

def unwrapped_rel
  @unwrapped_rel
end

Instance Method Details

#build!Object

TODO: This feels like it should also wrap the rel, but that is handled in ActiveGraph::Relationship::Persistence at the moment. Builds and executes the query using the objects giving during init. It holds the process:

  • Execute node callbacks if needed

  • Create and execute the query

  • Mix the query response into the unpersisted objects given during init



21
22
23
24
25
26
27
# File 'lib/active_graph/relationship/persistence/query_factory.rb', line 21

def build!
  node_before_callbacks! do
    res = query_factory(rel, rel_id, iterative_query).query.unwrapped.return(*unpersisted_return_ids).first
    node_symbols.each { |n| wrap!(send(n), res, n) }
    @unwrapped_rel = res[rel_id]
  end
end