Module: Env::Variables
- Included in:
- Env
- Defined in:
- lib/env/variables.rb
Instance Method Summary collapse
-
#browser ⇒ String?
The default browser to use.
-
#columns ⇒ Integer
The number of columns in the terminal.
-
#debug? ⇒ Boolean
Determines whether optional Debugging was enabled.
-
#editor ⇒ String?
The default editor to use.
-
#env ⇒ Hash{String => String}
The environment variables.
-
#home ⇒ Pathname
The home directory.
-
#host_name ⇒ String
The host-name of the system.
-
#lang ⇒ Array<String, String>
The default language.
-
#ld_library_paths ⇒ Array<Pathname>
The directories to search within for libraries.
-
#lines ⇒ Integer
The number of lines in the terminal.
-
#parse_paths(paths) ⇒ Array<Pathname>
protected
Parses a String containing multiple paths.
-
#paths ⇒ Array<Pathname>
The directories to search within for executables.
-
#shell ⇒ String?
The path of the default shell.
-
#shell_name ⇒ String?
The name of the default shell.
-
#terminal ⇒ String?
The default terminal to use.
-
#timezone ⇒ String?
The default timezone.
-
#user ⇒ String
The name of the current user.
Instance Method Details
#browser ⇒ String?
The default browser to use.
182 183 184 |
# File 'lib/env/variables.rb', line 182 def browser env['BROWSER'] end |
#columns ⇒ Integer
The number of columns in the terminal.
122 123 124 |
# File 'lib/env/variables.rb', line 122 def columns env['COLUMNS'].to_i if env['COLUMNS'] end |
#debug? ⇒ Boolean
Determines whether optional Debugging was enabled.
194 195 196 |
# File 'lib/env/variables.rb', line 194 def debug? true if env['DEBUG'] end |
#editor ⇒ String?
The default editor to use.
172 173 174 |
# File 'lib/env/variables.rb', line 172 def editor env['EDITOR'] end |
#env ⇒ Hash{String => String}
The environment variables.
13 14 15 |
# File 'lib/env/variables.rb', line 13 def env ENV end |
#home ⇒ Pathname
The home directory.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/env/variables.rb', line 69 def home # logic adapted from Gem.find_home. path = if (env['HOME'] || env['USERPROFILE']) env['HOME'] || env['USERPROFILE'] elsif (env['HOMEDRIVE'] && env['HOMEPATH']) "#{env['HOMEDRIVE']}#{env['HOMEPATH']}" else begin File.('~') rescue if File::ALT_SEPARATOR 'C:/' else '/' end end end return Pathname.new(path) end |
#host_name ⇒ String
The host-name of the system.
45 46 47 |
# File 'lib/env/variables.rb', line 45 def host_name env['HOSTNAME'] end |
#lang ⇒ Array<String, String>
The default language.
96 97 98 99 100 101 102 |
# File 'lib/env/variables.rb', line 96 def lang if (lang = env['LANG']) lang.split('.',2) else [] end end |
#ld_library_paths ⇒ Array<Pathname>
The directories to search within for libraries.
33 34 35 |
# File 'lib/env/variables.rb', line 33 def ld_library_paths parse_paths(env['LD_LIBRARY_PATH']) end |
#lines ⇒ Integer
The number of lines in the terminal.
132 133 134 |
# File 'lib/env/variables.rb', line 132 def lines env['LINES'].to_i if env['LINES'] end |
#parse_paths(paths) ⇒ Array<Pathname> (protected)
Parses a String containing multiple paths.
206 207 208 209 210 211 212 213 214 |
# File 'lib/env/variables.rb', line 206 def parse_paths(paths) if paths paths.split(File::PATH_SEPARATOR).map do |path| Pathname.new(path) end else [] end end |
#paths ⇒ Array<Pathname>
The directories to search within for executables.
23 24 25 |
# File 'lib/env/variables.rb', line 23 def paths parse_paths(env['PATH']) end |
#shell ⇒ String?
The path of the default shell.
142 143 144 |
# File 'lib/env/variables.rb', line 142 def shell env['SHELL'] end |
#shell_name ⇒ String?
The name of the default shell.
152 153 154 |
# File 'lib/env/variables.rb', line 152 def shell_name File.basename(shell) if shell end |
#terminal ⇒ String?
The default terminal to use.
162 163 164 |
# File 'lib/env/variables.rb', line 162 def terminal env['COLORTERM'] || env['TERM'] end |
#timezone ⇒ String?
The default timezone.
112 113 114 |
# File 'lib/env/variables.rb', line 112 def timezone env['TZ'] end |
#user ⇒ String
The name of the current user.
57 58 59 60 61 |
# File 'lib/env/variables.rb', line 57 def user # USER is used on GNU/Linux and Windows # LOGNAME is the POSIX user-name ENV variable env['USER'] || env['LOGNAME'] end |