Class: TTY::Terminal::Home
- Inherits:
-
Object
- Object
- TTY::Terminal::Home
- Defined in:
- lib/tty/terminal/home.rb
Overview
A class responsible for locating user home
Instance Method Summary collapse
-
#find_home ⇒ Object
Find user home.
-
#initialize(platform = nil) ⇒ Home
constructor
A new instance of Home.
- #unix_home ⇒ Object
- #windows_home ⇒ Object
Constructor Details
Instance Method Details
#find_home ⇒ Object
Find user home
15 16 17 18 |
# File 'lib/tty/terminal/home.rb', line 15 def find_home path = @platform.windows? ? windows_home : unix_home File.(path) end |
#unix_home ⇒ Object
20 21 22 23 24 25 |
# File 'lib/tty/terminal/home.rb', line 20 def unix_home require 'etc' "~#{Etc.getlogin}" rescue ENV['HOME'] end |
#windows_home ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/tty/terminal/home.rb', line 27 def windows_home if (home = ENV['HOME']) home.tr('\\', '/') elsif ENV['HOMEDRIVE'] && ENV['HOMEPATH'] File.join(ENV['HOMEDRIVE'], ENV['HOMEPATH']) elsif ENV['USERPROFILE'] ENV['USERPROFILE'] elsif ENV['HOMEDRIVE'] || ENV['SystemDrive'] File.join(ENV['HOMEDRIVE'] || ENV['SystemDrive'], '/') else 'C:/' end end |