lib/env/variables.rb in env-0.2.0 vs lib/env/variables.rb in env-0.3.0

- old
+ new

@@ -6,46 +6,74 @@ # The environment variables. # # @return [Hash{String => String}] # The Hash of environment variable names and values. # - def env_hash + # @api semipublic + # + def env ENV end # # The directories to search within for executables. # # @return [Array<Pathname>] # The paths of the directories. # def paths - parse_paths(env_hash['PATH']) + parse_paths(env['PATH']) end # # The directories to search within for libraries. # # @return [Array<Pathname>] # The paths of the directories. # def ld_library_paths - parse_paths(env_hash['LD_LIBRARY_PATH']) + parse_paths(env['LD_LIBRARY_PATH']) end # + # The host-name of the system. + # + # @return [String] + # The host-name. + # + # @since 0.3.0 + # + def host_name + env['HOSTNAME'] + end + + # + # The name of the current user. + # + # @return [String] + # The name of the user. + # + # @since 0.3.0 + # + def user + # USER is used on GNU/Linux and Windows + # LOGNAME is the POSIX user-name ENV variable + env['USER'] || env['LOGNAME'] + end + + # # The home directory. # # @return [Pathname] # The path of the home directory. # def home # logic adapted from Gem.find_home. - path = if (env_hash['HOME'] || env_hash['USERPROFILE']) - env_hash['HOME'] || env_hash['USERPROFILE'] - elsif (env_hash['HOMEDRIVE'] && env_hash['HOMEPATH']) - "#{env_hash['HOMEDRIVE']}#{env_hash['HOMEPATH']}" + path = if (env['HOME'] || env['USERPROFILE']) + env['HOME'] || env['USERPROFILE'] + elsif (env['HOMEDRIVE'] && env['HOMEPATH']) + "#{env['HOMEDRIVE']}#{env['HOMEPATH']}" else begin File.expand_path('~') rescue if File::ALT_SEPARATOR @@ -64,11 +92,11 @@ # # @return [Array<String, String>] # The language name and encoding. # def lang - if (lang = env_hash['LANG']) + if (lang = env['LANG']) lang.split('.',2) else [] end end @@ -90,31 +118,31 @@ # # @return [Integer] # The number of columns. # def columns - env_hash['COLUMNS'].to_i if env_hash['COLUMNS'] + env['COLUMNS'].to_i if env['COLUMNS'] end # # The number of lines in the terminal. # # @return [Integer] # The number of lines. # def lines - env_hash['LINES'].to_i if env_hash['LINES'] + env['LINES'].to_i if env['LINES'] end # # The path of the default shell. # # @return [String, nil] # The path to the default shell. # def shell - env_hash['SHELL'] + env['SHELL'] end # # The name of the default shell. # @@ -130,31 +158,31 @@ # # @return [String, nil] # The name of the terminal program. # def terminal - env_hash['COLORTERM'] || env_hash['TERM'] + env['COLORTERM'] || env['TERM'] end # # The default editor to use. # # @return [String, nil] # The name of the editor program. # def editor - env_hash['EDITOR'] + env['EDITOR'] end # # The default browser to use. # # @return [String, nil] # The name of the browser program. # def browser - env_hash['BROWSER'] + env['BROWSER'] end # # Determines whether optional Debugging was enabled. # @@ -162,10 +190,10 @@ # Specifies whether the `DEBUG` variable was specified. # # @since 0.2.0 # def debug? - true if env_hash['DEBUG'] + true if env['DEBUG'] end protected #