class OpenSession::Home

This singleton class ascertains the users home folder in a manner agnositic to whether the software is running on Linux or Windows.

Attributes

folder[R]
username[R]

Public Class Methods

dir() click to toggle source

This static behaviour reads the [home folder] just once.

# File lib/session/user.home.rb, line 17
def self.dir
  return Home.instance.folder
end
new() click to toggle source

Ascertain the home folder location.

# File lib/session/user.home.rb, line 30
def initialize

  # On Windows the home folder may end with [AppData/Roaming].
  extraneous_path = "/AppData/Roaming"

  @folder  = Dir.home
  @username = @folder.split("/").last
  return unless Dir.home.end_with? extraneous_path

  # Remove the tail [AppData/Roaming] from the home path.
  @folder = Dir.home.gsub extraneous_path, ""
  @username = @folder.split("/").last

end
usr() click to toggle source

This static behaviour reads the [username] just once.

# File lib/session/user.home.rb, line 22
def self.usr
  return Home.instance.username
end