Class: Neo4j::Node

Inherits:
Object
  • Object
show all
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

Server::CypherNode

Defined Under Namespace

Modules: Wrapper

Constant Summary

Constants included from PropertyValidator

PropertyValidator::VALID_PROPERTY_VALUE_CLASSES

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PropertyContainer

#[], #[]=

Methods included from PropertyValidator

#valid_property?, #validate_property

Methods included from Wrapper

#neo4j_obj, #wrapper

Methods included from EntityEquality

#==

Constructor Details

#initializeNode

Returns a new instance of Node.



205
206
207
# File 'lib/neo4j/node.rb', line 205

def initialize
  raise "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

Returns:



195
196
197
# File 'lib/neo4j/node.rb', line 195

def _load(neo_id, session = Neo4j::Session.current!)
  session.load_node(neo_id)
end

.create(props = nil, *labels_or_db) ⇒ Object

Creates a node



182
183
184
185
# File 'lib/neo4j/node.rb', line 182

def create(props=nil, *labels_or_db)
  session = Neo4j::Core::ArgumentHelper.session(labels_or_db)
  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



200
201
202
# File 'lib/neo4j/node.rb', line 200

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



188
189
190
191
# File 'lib/neo4j/node.rb', line 188

def load(neo_id, session = Neo4j::Session.current!)
  node = _load(neo_id, session)
  node && node.wrapper
end

Instance Method Details

#_rel(spec = {}) ⇒ Object



155
156
157
# File 'lib/neo4j/node.rb', line 155

def _rel(spec = {})
  raise 'not implemented'
end

#add_label(*labels) ⇒ Object

Adds one or more Neo4j labels on the node

Parameters:

  • labels (Array<Symbol>)

    one or more labels to add



97
98
99
# File 'lib/neo4j/node.rb', line 97

def add_label(*labels)
  raise 'not implemented'
end

#create_rel(type, other_node, props = nil) ⇒ Object

Creates a relationship of given type to other_node with optionally properties

Parameters:

  • type (Symbol)

    the type of the relation between the two nodes

  • other_node (Neo4j::Node)

    the other node

  • props (Hash<Symbol, Object>) (defaults to: nil)

    optionally properties for the created relationship



68
69
70
# File 'lib/neo4j/node.rb', line 68

def create_rel(type, other_node, props = nil)
  raise 'not implemented'
end

#delObject

Deletes this node from the database



119
120
121
# File 'lib/neo4j/node.rb', line 119

def del()
  raise 'not implemented'
end

#exist?Boolean

Returns true if the node exists.

Returns:

  • (Boolean)

    true if the node exists



124
125
126
# File 'lib/neo4j/node.rb', line 124

def exist?
  raise 'not implemented'
end

#get_property(key, value) ⇒ Object

Directly get the property on the node (low level method, may need transaction)

Parameters:

  • key (Symbol, String)

Returns:

  • the value of the key



60
61
62
# File 'lib/neo4j/node.rb', line 60

def get_property(key, value)
  raise 'not implemented'
end

#labelsObject

Returns all the Neo4j labels for this node.

Returns:

  • all the Neo4j labels for this node



114
115
116
# File 'lib/neo4j/node.rb', line 114

def labels()
  raise '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.”



146
147
148
# File 'lib/neo4j/node.rb', line 146

def node(specs = {})
  raise 'not implemented'
end

#nodes(specs = {}) ⇒ Enumerable<Neo4j::Node>

This method is abstract.
Note:

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

Parameters:

  • match (Hash)

    the options to create a message with.

Returns:

  • (Enumerable<Neo4j::Node>)

    an Enumeration of either Neo4j::Node objects or wrapped Neo4j::Node objects



176
177
178
# File 'lib/neo4j/node.rb', line 176

def nodes(specs = {})
  #rels(specs).map{|n| n.other_node(self)}
end

#propsHash<Symbol, Object>

Returns all properties of the node.

Returns:

  • (Hash<Symbol, Object>)

    all properties of the node



24
25
26
# File 'lib/neo4j/node.rb', line 24

def props()
  raise 'not implemented'
end

#props=(properties) ⇒ Object

replace all properties with new properties

Parameters:

  • properties (Hash<Symbol, Object>)

    a hash of properties the node should have



30
31
32
# File 'lib/neo4j/node.rb', line 30

def props=(properties)
  raise 'not implemented'
end

#refreshObject

Refresh the properties by reading it from the database again next time an property value is requested.



35
36
37
# File 'lib/neo4j/node.rb', line 35

def refresh
  raise '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.



151
152
153
# File 'lib/neo4j/node.rb', line 151

def rel(spec = {})
  raise 'not implemented'
end

#rel?(spec = {}) ⇒ Boolean

Returns true or false if there is one or more relationships

Returns:

  • (Boolean)


161
162
163
# File 'lib/neo4j/node.rb', line 161

def rel?(spec = {})
  raise 'not implemented'
end

#rels(match = {dir: :both}) ⇒ Enumerable<Neo4j::Relationship>

Returns an enumeration of relationships. It always returns relationships of depth one.

Examples:

Return both incoming and outgoing relationships of any type

node_a.rels

All outgoing or incoming relationship of type friends

node_a.rels(type: :friends)

All outgoing relationships between me and another node of type friends

node_a.rels(type: :friends, dir: :outgoing, between: node_b)

Parameters:

  • match (Hash) (defaults to: {dir: :both})

    the options to create a message with.

Options Hash (match):

  • :dir (Symbol)

    dir the direction of the relationship, allowed values: :both, :incoming, :outgoing.

  • :type (Symbol)

    the type of relationship to navigate

  • :between (Symbol)

    return all the relationships between this and given node

Returns:



91
92
93
# File 'lib/neo4j/node.rb', line 91

def rels(match = {dir: :both})
  raise 'not implemented'
end

#remove_label(*labels) ⇒ Object

Removes given labels



108
109
110
# File 'lib/neo4j/node.rb', line 108

def remove_label(*labels)
  raise 'not implemented'
end

#remove_property(key) ⇒ Object

Directly remove the property on the node (low level method, may need transaction)



46
47
48
# File 'lib/neo4j/node.rb', line 46

def remove_property(key)
  raise 'not implemented'
end

#set_label(*labels) ⇒ Object

Sets label on the node. Any old labels will be removed

Parameters:

  • labels (Array<Symbol>)

    one or more labels to set



103
104
105
# File 'lib/neo4j/node.rb', line 103

def set_label(*labels)
  raise 'not implemented'
end

#set_property(key, value) ⇒ Object

Directly set the property on the node (low level method, may need transaction)

Parameters:

  • key (Symbol, String)
  • value

    see Neo4j::PropertyValidator::VALID_PROPERTY_VALUE_CLASSES for valid values



53
54
55
# File 'lib/neo4j/node.rb', line 53

def set_property(key, value)
  raise 'not implemented'
end

#update_props(properties) ⇒ Object

Updates the properties, keeps old properties

Parameters:

  • properties (Hash<Symbol, Object>)

    hash of properties that should be updated on the node



41
42
43
# File 'lib/neo4j/node.rb', line 41

def update_props(properties)
  raise 'not implemented'
end