forked from larsch/ocra
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement BuildHelper with set_env_path method
Implemented BuildHelper module and extended it to builder objects. The new set_env_path method provides specialized handling for environment variables that contain paths, utilizing the builder's export method. This functionality is specifically applied to the RUBYLIB and GEM_PATH variables, enhancing how paths are managed and set in the environment. This update ensures that path-related environment variables are handled more efficiently and consistently, streamlining the setup process for development environments and deployments.
- Loading branch information
Showing
2 changed files
with
37 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
module Ocran | ||
module BuildHelper | ||
# Sets an environment variable with a joined path value. | ||
# This method processes an array of path strings or Pathname objects, accepts | ||
# absolute paths as is, and appends a placeholder to relative paths to convert | ||
# them into absolute paths. The converted paths are then joined into a single | ||
# string using the system's path separator. | ||
# | ||
# @param name [String] the name of the environment variable to set. | ||
# @param paths [Array<String, Pathname>] an array of path arguments which can | ||
# be either absolute or relative. | ||
# | ||
# Example: | ||
# set_env_path("RUBYLIB", "lib", "ext", "vendor/lib") | ||
# # This sets RUBYLIB to a string such as "C:/ProjectRoot/lib;C:/ProjectRoot/ext;C:/ProjectRoot/vendor/lib" | ||
# # assuming each path is correctly converted to an absolute path through a placeholder. | ||
# | ||
def set_env_path(name, *paths) | ||
value = paths.map { |path| | ||
if File.absolute_path?(path) | ||
path | ||
else | ||
File.join(TEMPDIR_ROOT, path) | ||
end | ||
}.join(File::PATH_SEPARATOR) | ||
|
||
export(name, value) | ||
end | ||
end | ||
end |