Class: OpenSession::Home

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/session/user.home.rb

Overview

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHome

Ascertain the home folder location.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# 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

Instance Attribute Details

#folderObject (readonly)

Returns the value of attribute folder.



26
27
28
# File 'lib/session/user.home.rb', line 26

def folder
  @folder
end

#usernameObject (readonly)

Returns the value of attribute username.



27
28
29
# File 'lib/session/user.home.rb', line 27

def username
  @username
end

Class Method Details

.dirObject

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



17
18
19
# File 'lib/session/user.home.rb', line 17

def self.dir
  return Home.instance.folder
end

.usrObject

This static behaviour reads the [username] just once.



22
23
24
# File 'lib/session/user.home.rb', line 22

def self.usr
  return Home.instance.username
end