Method: GLib.prepend_path_to_environment_variable

Defined in:
lib/glib2.rb

.prepend_path_to_environment_variable(path, environment_name) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/glib2.rb', line 88

def prepend_path_to_environment_variable(path, environment_name)
  path = Pathname(path) unless path.is_a?(Pathname)
  return unless path.exist?

  dir = path.to_s
  dir = dir.gsub(/\//, ::File::ALT_SEPARATOR) if ::File::ALT_SEPARATOR

  separator = ::File::PATH_SEPARATOR
  paths = (ENV[environment_name] || '').split(separator)
  unless paths.include?(dir)
    paths = [dir] + paths
    ENV[environment_name] = paths.join(separator)
  end
end