Class: Neo4j::Node
- Inherits:
-
Object
- Object
- Neo4j::Node
- Includes:
- EntityEquality, 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
Constant Summary
Constants included from PropertyValidator
PropertyValidator::VALID_PROPERTY_VALUE_CLASSES
Class Method Summary (collapse)
-
+ (Neo4j::Node) _load(neo_id, session = Neo4j::Session.current!)
Same as #load but does not try to return a wrapped node.
-
+ (Object) create(props = nil, *labels_or_db)
Creates a node.
-
+ (Object) find_nodes(label, value = nil, session = Neo4j::Session.current!)
Find the node with given label and value.
-
+ (Object) load(neo_id, session = Neo4j::Session.current!)
Loads a node from the database with given id.
Instance Method Summary (collapse)
- - (Object) _rel(spec = {})
-
- (Object) add_label(*labels)
Adds one or more Neo4j labels on the node.
-
- (Object) create_rel(type, other_node, props = nil)
Creates a relationship of given type to other_node with optionally properties.
-
- (Object) del
Deletes this node from the database.
-
- (Boolean) exist?
True if the node exists.
-
- (Object) get_property(key, value)
Directly get the property on the node (low level method, may need transaction).
-
- (Node) initialize
constructor
A new instance of Node.
-
- (Object) labels
All the Neo4j labels for this node.
-
- (Object) node(specs = {})
Returns the only node of a given type and direction that is attached to this node, or nil.
-
- (Enumerable<Neo4j::Node>) nodes(specs = {})
abstract
Works like #rels method but instead returns the nodes.
-
- (Hash<Symbol, Object>) props
All properties of the node.
-
- (Object) props=(properties)
replace all properties with new properties.
-
- (Object) refresh
Refresh the properties by reading it from the database again next time an property value is requested.
-
- (Object) rel(spec = {})
Same as #node but returns the relationship.
-
- (Boolean) rel?(spec = {})
Returns true or false if there is one or more relationships.
-
- (Enumerable<Neo4j::Relationship>) rels(match = {dir: :both})
Returns an enumeration of relationships.
-
- (Object) remove_label(*labels)
Removes given labels.
-
- (Object) remove_property(key)
Directly remove the property on the node (low level method, may need transaction).
-
- (Object) set_label(*labels)
Sets label on the node.
-
- (Object) set_property(key, value)
Directly set the property on the node (low level method, may need transaction).
-
- (Object) update_props(properties)
Updates the properties, keeps old properties.
Methods included from PropertyContainer
Methods included from PropertyValidator
#valid_property?, #validate_property
Methods included from Wrapper
Methods included from EntityEquality
Constructor Details
- (Node) initialize
Returns a new instance of Node
203 204 205 |
# File 'lib/neo4j/node.rb', line 203 def initialize fail "Can't instantiate abstract class" if abstract_class? end |
Class Method Details
+ (Neo4j::Node) _load(neo_id, session = Neo4j::Session.current!)
Same as #load but does not try to return a wrapped node
193 194 195 |
# File 'lib/neo4j/node.rb', line 193 def _load(neo_id, session = Neo4j::Session.current!) session.load_node(neo_id) end |
+ (Object) create(props = nil, *labels_or_db)
Creates a node
180 181 182 183 |
# File 'lib/neo4j/node.rb', line 180 def create(props = nil, *labels_or_db) session = Neo4j::Core::ArgumentHelper.session(labels_or_db) session.create_node(props, labels_or_db) end |
+ (Object) find_nodes(label, value = nil, session = Neo4j::Session.current!)
Find the node with given label and value
198 199 200 |
# File 'lib/neo4j/node.rb', line 198 def find_nodes(label, value = nil, session = Neo4j::Session.current!) session.find_nodes(label, value) end |
+ (Object) load(neo_id, session = Neo4j::Session.current!)
Loads a node from the database with given id
186 187 188 189 |
# File 'lib/neo4j/node.rb', line 186 def load(neo_id, session = Neo4j::Session.current!) node = _load(neo_id, session) node && node.wrapper end |
Instance Method Details
- (Object) _rel(spec = {})
153 154 155 |
# File 'lib/neo4j/node.rb', line 153 def _rel(spec = {}) fail 'not implemented' end |
- (Object) add_label(*labels)
Adds one or more Neo4j labels on the node
95 96 97 |
# File 'lib/neo4j/node.rb', line 95 def add_label(*labels) fail 'not implemented' end |
- (Object) create_rel(type, other_node, props = nil)
Creates a relationship of given type to other_node with optionally properties
66 67 68 |
# File 'lib/neo4j/node.rb', line 66 def create_rel(type, other_node, props = nil) fail 'not implemented' end |
- (Object) del
Deletes this node from the database
117 118 119 |
# File 'lib/neo4j/node.rb', line 117 def del fail 'not implemented' end |
- (Boolean) exist?
Returns true if the node exists
122 123 124 |
# File 'lib/neo4j/node.rb', line 122 def exist? fail 'not implemented' end |
- (Object) get_property(key, value)
Directly get the property on the node (low level method, may need transaction)
58 59 60 |
# File 'lib/neo4j/node.rb', line 58 def get_property(key, value) fail 'not implemented' end |
- (Object) labels
Returns all the Neo4j labels for this node
112 113 114 |
# File 'lib/neo4j/node.rb', line 112 def labels fail 'not implemented' end |
- (Object) node(specs = {})
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.”
144 145 146 |
# File 'lib/neo4j/node.rb', line 144 def node(specs = {}) fail 'not implemented' end |
- (Enumerable<Neo4j::Node>) nodes(specs = {})
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
174 175 176 |
# File 'lib/neo4j/node.rb', line 174 def nodes(specs = {}) # rels(specs).map{|n| n.other_node(self)} end |
- (Hash<Symbol, Object>) props
Returns all properties of the node
22 23 24 |
# File 'lib/neo4j/node.rb', line 22 def props fail 'not implemented' end |
- (Object) props=(properties)
replace all properties with new properties
28 29 30 |
# File 'lib/neo4j/node.rb', line 28 def props=(properties) fail 'not implemented' end |
- (Object) refresh
Refresh the properties by reading it from the database again next time an property value is requested.
33 34 35 |
# File 'lib/neo4j/node.rb', line 33 def refresh fail 'not implemented' end |
- (Object) rel(spec = {})
Same as #node but returns the relationship. Notice it may raise an exception if there are more then one relationship matching.
149 150 151 |
# File 'lib/neo4j/node.rb', line 149 def rel(spec = {}) fail 'not implemented' end |
- (Boolean) rel?(spec = {})
Returns true or false if there is one or more relationships
159 160 161 |
# File 'lib/neo4j/node.rb', line 159 def rel?(spec = {}) fail 'not implemented' end |
- (Enumerable<Neo4j::Relationship>) rels(match = {dir: :both})
Returns an enumeration of relationships. It always returns relationships of depth one.
89 90 91 |
# File 'lib/neo4j/node.rb', line 89 def rels(match = {dir: :both}) fail 'not implemented' end |
- (Object) remove_label(*labels)
Removes given labels
106 107 108 |
# File 'lib/neo4j/node.rb', line 106 def remove_label(*labels) fail 'not implemented' end |
- (Object) remove_property(key)
Directly remove the property on the node (low level method, may need transaction)
44 45 46 |
# File 'lib/neo4j/node.rb', line 44 def remove_property(key) fail 'not implemented' end |
- (Object) set_label(*labels)
Sets label on the node. Any old labels will be removed
101 102 103 |
# File 'lib/neo4j/node.rb', line 101 def set_label(*labels) fail 'not implemented' end |
- (Object) set_property(key, value)
Directly set the property on the node (low level method, may need transaction)
51 52 53 |
# File 'lib/neo4j/node.rb', line 51 def set_property(key, value) fail 'not implemented' end |
- (Object) update_props(properties)
Updates the properties, keeps old properties
39 40 41 |
# File 'lib/neo4j/node.rb', line 39 def update_props(properties) fail 'not implemented' end |