Module: Neon::Session

Defined in:
lib/neon/session.rb,
lib/neon/session/rest.rb,
lib/neon/session/embedded.rb,
lib/neon/session/invalid_session.rb

Overview

A session established with a Neo4J database.

Defined Under Namespace

Classes: Embedded, InvalidSessionTypeError, Rest

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.currentObject

The current default session running right now.



9
10
11
# File 'lib/neon/session.rb', line 9

def current
  @current
end

Class Method Details

.classClass

Returns the class of the current session.

Returns:

  • (Class)

    the class of the current session.



32
33
34
# File 'lib/neon/session.rb', line 32

def class
  @current.class
end

.new(type, *args) ⇒ Session

Create a new session with the database.

Parameters:

  • type (:rest, :embedded)

    the type of session to create. Any other type will raise a InvalidSesionTypeError.

  • args (Array)

    other args to pass to the session - usually stuff like the address of the database.

Returns:

  • (Session)

    a new session of type type and to the database initiated with args.



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/neon/session.rb', line 17

def new(type, *args)
  session = case type
    when :rest
      Rest.new(*args)
    when :embedded
      Embedded.new(*args)
    else
      raise InvalidSessionTypeError.new(type)
    end
    # Set the current session unless one already exists
    @current = session unless @current
    session
end

.running?Boolean

Returns wether the current session is running or not.

Returns:

  • (Boolean)

    wether the current session is running or not.



37
38
39
40
41
42
43
# File 'lib/neon/session.rb', line 37

def running?
  if @current
    @current.running?
  else
    false
  end
end

.startBoolean

Starts the current session.

Returns:

  • (Boolean)

    wether the session started successfully or not.



47
48
49
50
51
52
53
# File 'lib/neon/session.rb', line 47

def start
  if @current
    @current.start
  else
    false
  end
end

.stopBoolean

Stops the current session

Returns:

  • (Boolean)

    wether the session stopped successfully or not.



57
58
59
60
61
62
63
64
65
# File 'lib/neon/session.rb', line 57

def stop
  if @current
    result = @current.stop
    @current = nil if result
    result
  else
    true
  end
end