Class: OpenSession::Home
- Inherits:
-
Object
- Object
- OpenSession::Home
- 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
-
#folder ⇒ Object
readonly
Returns the value of attribute folder.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Class Method Summary collapse
-
.dir ⇒ Object
This static behaviour reads the [home folder] just once.
-
.usr ⇒ Object
This static behaviour reads the [username] just once.
Instance Method Summary collapse
-
#initialize ⇒ Home
constructor
Ascertain the home folder location.
Constructor Details
#initialize ⇒ Home
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
#folder ⇒ Object (readonly)
Returns the value of attribute folder.
26 27 28 |
# File 'lib/session/user.home.rb', line 26 def folder @folder end |
#username ⇒ Object (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
.dir ⇒ Object
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 |
.usr ⇒ Object
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 |