module Nuggets::Env::UserHomeMixin

Public Instance Methods

user_home([default]) → aString click to toggle source

Returns the user's home directory, or default if it could not be found.

# File lib/nuggets/env/user_home_mixin.rb, line 35
def user_home(default = ::File::ALT_SEPARATOR ? 'C:/' : '/')
  begin
    return ::Dir.home
  rescue ::ArgumentError
    # "couldn't find HOME environment -- expanding `~'"
  end if ::Dir.respond_to?(:home)

  %w[HOME HOMEDRIVE:HOMEPATH USERPROFILE APPDATA].each { |key|
    home = values_at(*key.split(':')).join
    return home.gsub(/\/, '/') if home && !home.empty?
  }

  begin
    ::File.expand_path('~')
  rescue ::ArgumentError
    default
  end
end