Module: Neo4j::Core::Node::ClassMethods
- Included in:
- Node
- Defined in:
- lib/neo4j-core/node/class_methods.rb
Instance Method Summary collapse
-
#_load(node_id, db = Neo4j.started_db) ⇒ Object
Same as load but does not return the node as a wrapped Ruby object.
-
#exist?(entity_or_entity_id, db = Neo4j.started_db) ⇒ true, false
Checks if the given entity node or entity id (Neo4j::Node#neo_id) exists in the database.
-
#load(node_id, db = Neo4j.started_db) ⇒ Object, ...
Loads a node or wrapped node given a native java node or an id.
-
#new(*args) ⇒ Java::OrgNeo4jGraphdb::Node
(also: #create)
Returns a new neo4j Node.
Instance Method Details
#_load(node_id, db = Neo4j.started_db) ⇒ Object
Same as load but does not return the node as a wrapped Ruby object.
43 44 45 46 47 48 |
# File 'lib/neo4j-core/node/class_methods.rb', line 43 def _load(node_id, db = Neo4j.started_db) return nil if node_id.nil? db.graph.get_node_by_id(node_id.to_i) rescue Java::OrgNeo4jGraphdb.NotFoundException nil end |
#exist?(entity_or_entity_id, db = Neo4j.started_db) ⇒ true, false
Checks if the given entity node or entity id (Neo4j::Node#neo_id) exists in the database.
53 54 55 56 57 58 59 60 61 |
# File 'lib/neo4j-core/node/class_methods.rb', line 53 def exist?(entity_or_entity_id, db = Neo4j.started_db) id = entity_or_entity_id.kind_of?(Fixnum) ? entity_or_entity_id : entity_or_entity_id.id node = _load(id, db) return false unless node node.has_property?('a') true rescue java.lang.IllegalStateException nil # the node has been deleted end |
#load(node_id, db = Neo4j.started_db) ⇒ Object, ...
Loads a node or wrapped node given a native java node or an id. If there is a Ruby wrapper for the node then it will create and return a Ruby object that will wrap the java node.
69 70 71 72 |
# File 'lib/neo4j-core/node/class_methods.rb', line 69 def load(node_id, db = Neo4j.started_db) node = _load(node_id, db) node && node.wrapper end |
#new(*args) ⇒ Java::OrgNeo4jGraphdb::Node Also known as: create
Returns a new neo4j Node. The return node is actually an Java object of type Java::OrgNeo4jGraphdb::Node java object which has been extended (see the included mixins for Neo4j::Node).
The created node will have a unique id - Neo4j::Property#neo_id
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/neo4j-core/node/class_methods.rb', line 25 def new(*args) # the first argument can be an hash of properties to set props = args[0].respond_to?(:each_pair) && args[0] # a db instance can be given, is the first argument if that was not a hash, or otherwise the second db = (!props && args[0]) || args[1] || Neo4j.started_db node = db.graph.create_node props.each_pair { |k, v| node[k]= v } if props node end |