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

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

- (Node) initialize

Returns a new instance of Node



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

def initialize
  raise "Can't instantiate abstract class" if abstract_class?
  puts "Instantiated!"
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

Returns:



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

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

+ (Object) create(props = nil, *labels_or_db)

Creates a node



164
165
166
167
# File 'lib/neo4j/node.rb', line 164

def create(props=nil, *labels_or_db)
  session = Neo4j::Core::ArgumentHelper.session(labels_or_db)
  session.create_node(props, labels_or_db)
end

+ (true, false) exist?(entity_or_entity_id, session = Neo4j::Session.current)

Checks if the given entity node or entity id (Neo4j::Node#neo_id) exists in the database.

Returns:

  • (true, false)

    if exist



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

def exist?(entity_or_entity_id, session = Neo4j::Session.current)
  session.node_exist?(neo_id)
end

+ (Object) find_nodes(label, value = nil, session = Neo4j::Session.current)

Find the node with given label and value



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

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



170
171
172
173
# File 'lib/neo4j/node.rb', line 170

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

Instance Method Details

- (Object) _rel(spec = {})



137
138
139
# File 'lib/neo4j/node.rb', line 137

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

- (Object) add_label(*labels)

Adds one or more Neo4j labels on the node



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

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

- (Object) create_rel(type, other_node, props = nil)

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) (defaults to: nil)

    optionally properties for the created relationship



63
64
65
# File 'lib/neo4j/node.rb', line 63

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

- (Object) del

Deletes this node from the database



101
102
103
# File 'lib/neo4j/node.rb', line 101

def del()
  raise 'not implemented'
end

- (Boolean) exist?

Same as Neo4j::Node#exist?

Returns:

  • (Boolean)


106
107
108
# File 'lib/neo4j/node.rb', line 106

def exist?
  raise 'not implemented'
end

- (Object) get_property(key, value)

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

Parameters:

  • key (Hash, String)

Returns:

  • the value of the key



55
56
57
# File 'lib/neo4j/node.rb', line 55

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

- (Object) labels



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

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



128
129
130
# File 'lib/neo4j/node.rb', line 128

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

- (Enumerable) nodes(specs = {})

This method is abstract.

Works like #rels method but instead returns the nodes. It does try to load a Ruby wrapper around each node

Parameters:

  • opts (Hash)

    the options to create a message with.

Returns:

  • (Enumerable)

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



158
159
160
# File 'lib/neo4j/node.rb', line 158

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

- (Hash) props

Returns all properties of the node

Returns:

  • (Hash)

    all properties of the node



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

def props()
  raise 'not implemented'
end

- (Object) props=(hash)

replace all properties with new properties

Parameters:

  • hash (Hash)

    a hash of properties the node should have



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

def props=(hash)
  raise '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.



133
134
135
# File 'lib/neo4j/node.rb', line 133

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

- (Boolean) rel?(spec = {})

Returns true or false if there is one or more relationships Same as `!! #rel()`

Returns:

  • (Boolean)


143
144
145
# File 'lib/neo4j/node.rb', line 143

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

- (Enumerable) rels(match = {dir: :both})

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:

  • opts (Hash)

    the options to create a message with.

Returns:

  • (Enumerable)

    of Neo4j::Relationship objects



86
87
88
# File 'lib/neo4j/node.rb', line 86

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

- (Object) remove_property(key)

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



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

def remove_property(key)
  raise 'not implemented'
end

- (Object) set_property(key, value)

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

Parameters:

  • key (Hash, String)
  • value

    see Neo4j::PropertyValidator::VALID_PROPERTY_VALUE_CLASSES for valid values



48
49
50
# File 'lib/neo4j/node.rb', line 48

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

- (Object) update_props(hash)

Updates the properties, keeps old properties

Parameters:

  • hash (Hash)

    hash of properties that should be updated on the node



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

def update_props(hash)
  raise 'not implemented'
end