Module: Neon::Node

Extended by:
ArgumentHelpers
Defined in:
lib/neon/node.rb,
lib/neon/node/rest.rb

Defined Under Namespace

Classes: Rest

Class Method Summary collapse

Methods included from ArgumentHelpers

extract_session

Class Method Details

.load(id, session = Neon::Session.current) ⇒ Node

Loads an existing node with the given id

Parameters:

  • id (Integer)

    the id of the node to be loaded and returned.

  • session (Session) (defaults to: Neon::Session.current)

    an optional session from where to load the node.

Returns:

  • (Node)

    an existing node with the given id and specified session. It returns nil if the node is not found.



33
34
35
36
37
38
39
# File 'lib/neon/node.rb', line 33

def load(id, session = Neon::Session.current)
  begin
    session.load(id)
  rescue NoMethodError => e
    _raise_invalid_session_error(session, e)
  end
end

.new(attributes, labels, session) ⇒ Node

Creates a new Node in the database. All subsequent changes are immediately persisted.

Parameters:

  • attributes (Hash)

    the properties to initialize the node with.

  • labels (String, Symbol, Array<String, Symbol>)

    an optional list of labels or an array of labels. Labels can be strings or symbols.

  • session (Session)

    an optional session can be provided as the last value to indicate the database where to create the node. If none is provided then the current session is assumed.

Returns:

  • (Node)

    a new node.



17
18
19
20
21
22
23
24
25
# File 'lib/neon/node.rb', line 17

def new(attributes, *args)
  session = extract_session(args)
  labels = args.flatten
  begin
    session.create_node(attributes, labels)
  rescue NoMethodError => e
    _raise_invalid_session_error(session, e)
  end
end