Class: Neo4j::Node
- Inherits:
-
Object
- Object
- Neo4j::Node
- Includes:
- EntityEquality, EntityMarshal, Wrapper, PropertyContainer
- Defined in:
- lib/neo4j/node.rb
Overview
The base class for both the Embedded and Server Neo4j Node Notice this class is abstract and can’t be instantiated
Direct Known Subclasses
Defined Under Namespace
Modules: Wrapper
Constant Summary
Constants included from PropertyValidator
PropertyValidator::VALID_PROPERTY_VALUE_CLASSES
Class Method Summary collapse
-
._load(neo_id, session = Neo4j::Session.current!) ⇒ Neo4j::Node
Same as #load but does not try to return a wrapped node.
-
.create(props = nil, *labels_or_db) ⇒ Object
Creates a node.
-
.find_nodes(label, value = nil, session = Neo4j::Session.current!) ⇒ Object
Find the node with given label and value.
-
.load(neo_id, session = Neo4j::Session.current!) ⇒ Object
Loads a node from the database with given id.
- .validate_match!(match) ⇒ Object
Instance Method Summary collapse
- #_rel(spec = {}) ⇒ Object
-
#add_label(*labels) ⇒ Object
Adds one or more Neo4j labels on the node.
-
#create_rel(type, other_node, props = nil) ⇒ Object
Creates a relationship of given type to other_node with optionally properties.
-
#del ⇒ Object
Deletes this node from the database.
-
#exist? ⇒ Boolean
True if the node exists in the database.
-
#get_property(key, value) ⇒ Object
Directly get the property on the node (low level method, may need transaction).
-
#initialize ⇒ Node
constructor
A new instance of Node.
-
#labels ⇒ Array<Symbol>
All labels on the node.
-
#node(specs = {}) ⇒ Object
Returns the only node of a given type and direction that is attached to this node, or nil.
-
#nodes(specs = {}) ⇒ Enumerable<Neo4j::Node>
abstract
Works like #rels method but instead returns the nodes.
-
#props ⇒ Hash<Symbol, Object>
All properties of the node.
-
#props=(properties) ⇒ Object
replace all properties with new properties.
-
#refresh ⇒ Object
Refresh the properties by reading it from the database again next time an property value is requested.
-
#rel(spec = {}) ⇒ Object
Same as #node but returns the relationship.
-
#rel?(spec = {}) ⇒ Boolean
Returns true or false if there is one or more relationships.
-
#rels(match = {dir: :both}) ⇒ Enumerable<Neo4j::Relationship>
Returns an enumeration of relationships.
-
#remove_label(*labels) ⇒ Object
Removes given labels.
-
#remove_property(key) ⇒ Object
Directly remove the property on the node (low level method, may need transaction).
-
#set_label(*labels) ⇒ Object
Sets label on the node.
-
#set_property(key, value) ⇒ Object
Directly set the property on the node (low level method, may need transaction).
-
#update_props(properties) ⇒ Object
Updates the properties, keeps old properties.
Methods included from EntityMarshal
Methods included from PropertyContainer
Methods included from PropertyValidator
#valid_property?, #validate_property!
Methods included from Wrapper
Methods included from EntityEquality
Constructor Details
#initialize ⇒ Node
Returns a new instance of Node.
206 207 208 |
# File 'lib/neo4j/node.rb', line 206 def initialize fail "Can't instantiate abstract class" if abstract_class? end |
Class Method Details
._load(neo_id, session = Neo4j::Session.current!) ⇒ Neo4j::Node
Same as #load but does not try to return a wrapped node
189 190 191 |
# File 'lib/neo4j/node.rb', line 189 def _load(neo_id, session = Neo4j::Session.current!) session.load_node(neo_id) end |
.create(props = nil, *labels_or_db) ⇒ Object
Creates a node
171 172 173 174 175 176 177 178 179 |
# File 'lib/neo4j/node.rb', line 171 def create(props = nil, *labels_or_db) session = if labels_or_db.last.is_a?(Neo4j::Session) labels_or_db.pop else Neo4j::Session.current! end session.create_node(props, labels_or_db) end |
.find_nodes(label, value = nil, session = Neo4j::Session.current!) ⇒ Object
Find the node with given label and value
194 195 196 |
# File 'lib/neo4j/node.rb', line 194 def find_nodes(label, value = nil, session = Neo4j::Session.current!) session.find_nodes(label, value) end |
.load(neo_id, session = Neo4j::Session.current!) ⇒ Object
Loads a node from the database with given id
182 183 184 185 |
# File 'lib/neo4j/node.rb', line 182 def load(neo_id, session = Neo4j::Session.current!) node = _load(neo_id, session) node && node.wrapper end |
.validate_match!(match) ⇒ Object
198 199 200 201 202 203 |
# File 'lib/neo4j/node.rb', line 198 def validate_match!(match) invalid_match_keys = match.keys - [:type, :dir, :between] fail "Invalid match keys: #{invalid_match_keys.inspect}" if !invalid_match_keys.empty? fail "Invalid dir: #{match[:dir]}" if ![nil, :incoming, :outgoing, :both].include?(match[:dir]) end |
Instance Method Details
#_rel(spec = {}) ⇒ Object
149 150 151 |
# File 'lib/neo4j/node.rb', line 149 def _rel(spec = {}) fail 'not implemented' end |
#add_label(*labels) ⇒ Object
Adds one or more Neo4j labels on the node
96 97 98 |
# File 'lib/neo4j/node.rb', line 96 def add_label(*labels) fail 'not implemented' end |
#create_rel(type, other_node, props = nil) ⇒ Object
Creates a relationship of given type to other_node with optionally properties
67 68 69 |
# File 'lib/neo4j/node.rb', line 67 def create_rel(type, other_node, props = nil) fail 'not implemented' end |
#del ⇒ Object
Deletes this node from the database
118 119 120 |
# File 'lib/neo4j/node.rb', line 118 def del fail 'not implemented' end |
#exist? ⇒ Boolean
Returns true if the node exists in the database.
123 124 125 |
# File 'lib/neo4j/node.rb', line 123 def exist? fail 'not implemented' end |
#get_property(key, value) ⇒ Object
Directly get the property on the node (low level method, may need transaction)
59 60 61 |
# File 'lib/neo4j/node.rb', line 59 def get_property(key, value) fail 'not implemented' end |
#labels ⇒ Array<Symbol>
Returns all labels on the node.
113 114 115 |
# File 'lib/neo4j/node.rb', line 113 def labels fail 'not implemented' end |
#node(specs = {}) ⇒ Object
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 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.”
140 141 142 |
# File 'lib/neo4j/node.rb', line 140 def node(specs = {}) fail 'not implemented' end |
#nodes(specs = {}) ⇒ Enumerable<Neo4j::Node>
it’s possible that the same node is returned more than once because of several relationship reaching to the same node, see #outgoing for alternative
Works like #rels method but instead returns the nodes. It does try to load a Ruby wrapper around each node
165 166 167 |
# File 'lib/neo4j/node.rb', line 165 def nodes(specs = {}) # rels(specs).map{|n| n.other_node(self)} end |
#props ⇒ Hash<Symbol, Object>
Returns all properties of the node.
23 24 25 |
# File 'lib/neo4j/node.rb', line 23 def props fail 'not implemented' end |
#props=(properties) ⇒ Object
replace all properties with new properties
29 30 31 |
# File 'lib/neo4j/node.rb', line 29 def props=(properties) fail 'not implemented' end |
#refresh ⇒ Object
Refresh the properties by reading it from the database again next time an property value is requested.
34 35 36 |
# File 'lib/neo4j/node.rb', line 34 def refresh fail 'not implemented' end |
#rel(spec = {}) ⇒ Object
Same as #node but returns the relationship. Notice it may raise an exception if there are more then one relationship matching.
145 146 147 |
# File 'lib/neo4j/node.rb', line 145 def rel(spec = {}) fail 'not implemented' end |
#rel?(spec = {}) ⇒ Boolean
Returns true or false if there is one or more relationships
155 156 157 |
# File 'lib/neo4j/node.rb', line 155 def rel?(spec = {}) fail 'not implemented' end |
#rels(match = {dir: :both}) ⇒ Enumerable<Neo4j::Relationship>
Returns an enumeration of relationships. It always returns relationships of depth one.
90 91 92 |
# File 'lib/neo4j/node.rb', line 90 def rels(match = {dir: :both}) fail 'not implemented' end |
#remove_label(*labels) ⇒ Object
Removes given labels
107 108 109 |
# File 'lib/neo4j/node.rb', line 107 def remove_label(*labels) fail 'not implemented' end |
#remove_property(key) ⇒ Object
Directly remove the property on the node (low level method, may need transaction)
45 46 47 |
# File 'lib/neo4j/node.rb', line 45 def remove_property(key) fail 'not implemented' end |
#set_label(*labels) ⇒ Object
Sets label on the node. Any old labels will be removed
102 103 104 |
# File 'lib/neo4j/node.rb', line 102 def set_label(*labels) fail 'not implemented' end |
#set_property(key, value) ⇒ Object
Directly set the property on the node (low level method, may need transaction)
52 53 54 |
# File 'lib/neo4j/node.rb', line 52 def set_property(key, value) fail 'not implemented' end |
#update_props(properties) ⇒ Object
Updates the properties, keeps old properties
40 41 42 |
# File 'lib/neo4j/node.rb', line 40 def update_props(properties) fail 'not implemented' end |