class Manga::Tools::SessionStore

A class on session retention.

Attributes

session_file_name[W]

@return [String] the session file name string

Public Class Methods

new() click to toggle source
# File lib/manga/tools/session_store.rb, line 12
def initialize
  create_session_dir_if_necessary
  @session_file_name = 'session.txt'
end

Public Instance Methods

exists?() click to toggle source

@return [Boolean] true if the session exists, otherwise returns false.

# File lib/manga/tools/session_store.rb, line 34
def exists?
  File.exist?(session_file_path)
end
load() click to toggle source

@return [String, nil] Returns the session ID if the session is stored, otherwise it returns nil

# File lib/manga/tools/session_store.rb, line 27
def load
  return nil unless exists?

  File.read(session_file_path)
end
session_file_path() click to toggle source

@return [String] the session file path

# File lib/manga/tools/session_store.rb, line 39
def session_file_path
  "#{session_dir}/#{@session_file_name}"
end
store(session_id) click to toggle source

Store a session.

# File lib/manga/tools/session_store.rb, line 18
def store(session_id)
  return if exists?

  File.open(session_file_path, 'w') do |f|
    f.write(session_id)
  end
end

Private Instance Methods

create_session_dir_if_necessary() click to toggle source
# File lib/manga/tools/session_store.rb, line 55
def create_session_dir_if_necessary
  FileUtils.mkdir_p(session_dir)
end
root_dir() click to toggle source

@return [String] the root directory

# File lib/manga/tools/session_store.rb, line 46
def root_dir
  @root_dir ||= "#{Dir.home}/.manga-tools"
end
session_dir() click to toggle source

@return [String] the session directory

# File lib/manga/tools/session_store.rb, line 51
def session_dir
  @session_dir ||= "#{root_dir}/session"
end