Module: Lich::Common::Frontend

Defined in:
documented/common/front-end.rb

Class Method Summary collapse

Class Method Details

.cleanup_session_filenil

Note:

If the session file is nil, the method will return without doing anything.

Cleans up (deletes) the current session file if it exists.

Returns:

  • (nil)


46
47
48
49
# File 'documented/common/front-end.rb', line 46

def self.cleanup_session_file
  return if @session_file.nil?
  File.delete(@session_file) if File.exist? @session_file
end

.create_session_file(name, host, port, display_session: true) ⇒ nil

Note:

If the name is nil, the method will return without doing anything.

Creates a session file with the given parameters.

Examples:

Creating a session file

Lich::Common::Frontend.create_session_file("my_session", "localhost", 3000)

Parameters:

  • name (String)

    The name of the session.

  • host (String)

    The host for the session.

  • port (Integer)

    The port for the session.

  • display_session (Boolean) (defaults to: true)

    Whether to display the session descriptor (default: true).

Returns:

  • (nil)


26
27
28
29
30
31
32
33
34
35
# File 'documented/common/front-end.rb', line 26

def self.create_session_file(name, host, port, display_session: true)
  return if name.nil?
  FileUtils.mkdir_p @tmp_session_dir
  @session_file = File.join(@tmp_session_dir, "%s.session" % name.downcase.capitalize)
  session_descriptor = { name: name, host: host, port: port }.to_json
  puts "writing session descriptor to %s\n%s" % [@session_file, session_descriptor] if display_session
  File.open(@session_file, "w") do |fd|
    fd << session_descriptor
  end
end

.session_file_locationString?

Returns the location of the current session file.

Returns:

  • (String, nil)

    The path to the session file or nil if not set.



39
40
41
# File 'documented/common/front-end.rb', line 39

def self.session_file_location
  @session_file
end