Module: Lich::Common::Frontend

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

Class Method Summary collapse

Class Method Details

.cleanup_session_filenil

Note:

This method will do nothing if there is no session file set.

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

Examples:

Lich::Common::Frontend.cleanup_session_file

Returns:

  • (nil)

    returns nothing



48
49
50
51
# File 'lib/common/front-end.rb', line 48

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

Creates a session file with the given name, host, and port.

Examples:

Lich::Common::Frontend.create_session_file("MySession", "localhost", 8080)

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)

    returns nothing

Raises:

  • (Errno::EACCES)

    if the session file cannot be created due to permission issues

  • (JSON::GeneratorError)

    if there is an error generating the JSON for the session descriptor



22
23
24
25
26
27
28
29
30
31
# File 'lib/common/front-end.rb', line 22

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.

Examples:

location = Lich::Common::Frontend.session_file_location

Returns:

  • (String, nil)

    the path to the session file or nil if not set



38
39
40
# File 'lib/common/front-end.rb', line 38

def self.session_file_location
  @session_file
end