Module: Neo4j::Rails::Relationships
- Extended by:
- ActiveSupport::Concern
- Included in:
- Model
- Defined in:
- lib/neo4j/rails/relationships/relationships.rb,
lib/neo4j/rails/relationships/storage.rb,
lib/neo4j/rails/relationships/rels_dsl.rb,
lib/neo4j/rails/relationships/node_dsl.rb
Overview
This module overrides the Neo4j::Core::Rels and Neo4j::Core::Traversal modules so that it can handle unpersisted relationships of depth one.
Defined Under Namespace
Classes: AllRelsDsl, NodesDSL, RelsDSL, Storage
Instance Method Summary (collapse)
-
- (Object) _incoming(rel_type)
Same as Neo4j::Core::Node#incoming Since the incoming method is redefined we might need the neo4j-core version of this method.
-
- (Object) _outgoing(rel_type)
Same as Neo4j::Core::Node#outgoing Since the incoming method is redefined we might need the neo4j-core version of this method.
-
- (NodesDSL) incoming(rel_type)
Similar to Neo4j::Core::Node#incoming but allows traversing both persisted and unpersisted relationship of depth one.
-
- (Object) node(dir, rel_type)
Returns the only node of a given type and direction that is attached to this node, or nil.
-
- (Enumerable) nodes(dir, rel_type)
Works like #rels method but instead returns the nodes.
-
- (NodesDSL) outgoing(rel_type)
Similar to Neo4j::Core::Node#outgoing but allows traversing both persisted and unpersisted relationship of depth one.
-
- (Neo4j::Relationship, ...) rel(dir, rel_type)
Returns the only relationship of a given type and direction that is attached to this node, or nil.
-
- (Boolean) rel?(dir = :both, rel_type = nil)
Check if the given relationship exists Returns true if there are one or more relationships from this node to other nodes with the given relationship.
-
- (RelsDSL, AllRelsDsl) rels(dir = :both, rel_type = nil)
Allow to access persisted and unpersisted relationships - like the #outgoing and #incoming method.
Instance Method Details
- (Object) _incoming(rel_type)
Same as Neo4j::Core::Node#incoming Since the incoming method is redefined we might need the neo4j-core version of this method.
31 32 33 |
# File 'lib/neo4j/rails/relationships/relationships.rb', line 31 def _incoming(rel_type) _core_incomig(rel_type) end |
- (Object) _outgoing(rel_type)
Same as Neo4j::Core::Node#outgoing Since the incoming method is redefined we might need the neo4j-core version of this method.
23 24 25 |
# File 'lib/neo4j/rails/relationships/relationships.rb', line 23 def _outgoing(rel_type) _core_outgoing(rel_type) end |
- (NodesDSL) incoming(rel_type)
Similar to Neo4j::Core::Node#incoming but allows traversing both persisted and unpersisted relationship of depth one. See #outgoing See, Neo4j::NodeRelationship#outgoing (when node is persisted) which returns a Neo4j::NodeTraverser
70 71 72 73 |
# File 'lib/neo4j/rails/relationships/relationships.rb', line 70 def incoming(rel_type) storage = _create_or_get_storage(rel_type) NodesDSL.new(storage, :incoming) end |
- (Object) node(dir, rel_type)
Returns the only node of a given type and direction that is attached to this node, or nil. This is a convenience method that is used in the commonly occuring situation where a node has exactly zero or one relationships of a given type and direction to another node. Typically this invariant is maintained by the rest of the code: if at any time more than one such relationships exist, it is a fatal error that should generate an exception. This method reflects that semantics and returns either:
-
nil if there are zero relationships of the given type and direction,
-
the relationship if there's exactly one, or
-
throws an unchecked exception in all other cases.
This method should be used only in situations with an invariant as described above. In those situations, a “state-checking” method (e.g. #rel?) is not required, because this method behaves correctly “out of the box.”
160 161 162 163 164 |
# File 'lib/neo4j/rails/relationships/relationships.rb', line 160 def node(dir, rel_type) raise "Illegal argument, first argument must be :both, :incoming or :outgoing, got #{dir.inspect}" unless [:incoming, :outgoing, :both].include?(dir) storage = _create_or_get_storage(rel_type) storage.single_node(dir) end |
- (Enumerable) nodes(dir, rel_type)
Works like #rels method but instead returns the nodes. It does try to load a Ruby wrapper around each node
141 142 143 144 145 |
# File 'lib/neo4j/rails/relationships/relationships.rb', line 141 def nodes(dir, rel_type) raise "Illegal argument, first argument must be :both, :incoming or :outgoing, got #{dir.inspect}" unless [:incoming, :outgoing, :both].include?(dir) storage = _create_or_get_storage(rel_type) NodesDSL.new(storage, dir) end |
- (NodesDSL) outgoing(rel_type)
Similar to Neo4j::Core::Node#outgoing but allows traversing both persisted and unpersisted relationship of depth one. For deeper or more advanced traversals see #_outgoing
57 58 59 60 |
# File 'lib/neo4j/rails/relationships/relationships.rb', line 57 def outgoing(rel_type) storage = _create_or_get_storage(rel_type) NodesDSL.new(storage, :outgoing) end |
- (Neo4j::Relationship, ...) rel(dir, rel_type)
it can return an unpersisted relationship
Returns the only relationship of a given type and direction that is attached to this node, or nil. This is a convenience method that is used in the commonly occuring situation where a node has exactly zero or one relationships of a given type and direction to another node. Typically this invariant is maintained by the rest of the code: if at any time more than one such relationships exist, it is a fatal error that should generate an unchecked exception. This method reflects that semantics and returns either:
-
nil if there are zero relationships of the given type and direction,
-
the relationship if there's exactly one, or
-
raise an exception in all other cases.
116 117 118 119 120 |
# File 'lib/neo4j/rails/relationships/relationships.rb', line 116 def rel(dir, rel_type) raise "Illegal argument, first argument must be :both, :incoming or :outgoing, got #{dir.inspect}" unless [:incoming, :outgoing, :both].include?(dir) storage = _create_or_get_storage(rel_type) storage.single_relationship(dir) end |
- (Boolean) rel?(dir = :both, rel_type = nil)
Check if the given relationship exists Returns true if there are one or more relationships from this node to other nodes with the given relationship.
129 130 131 132 133 |
# File 'lib/neo4j/rails/relationships/relationships.rb', line 129 def rel?(dir=:both, rel_type=nil) raise "Illegal argument, first argument must be :both, :incoming or :outgoing, got #{dir.inspect}" unless [:incoming, :outgoing, :both].include?(dir) storage = _create_or_get_storage(rel_type) !!storage.single_relationship(dir) end |
- (RelsDSL, AllRelsDsl) rels(dir = :both, rel_type = nil)
it can return an unpersisted relationship
Allow to access persisted and unpersisted relationships - like the #outgoing and #incoming method. To only find all the persisted relationship, node._java_entity.rels
91 92 93 94 95 96 97 98 99 |
# File 'lib/neo4j/rails/relationships/relationships.rb', line 91 def rels(dir=:both, rel_type=nil) raise "Illegal argument, first argument must be :both, :incoming or :outgoing, got #{dir.inspect}" unless [:incoming, :outgoing, :both].include?(dir) if rel_type.nil? AllRelsDsl.new(@_relationships, _java_node, dir) else storage = _create_or_get_storage(rel_type) RelsDSL.new(storage, dir) end end |