Class: Bundlebun::EnvPath
- Inherits:
-
Object
- Object
- Bundlebun::EnvPath
- Defined in:
- lib/bundlebun/env_path.rb
Overview
EnvPath exists to help prepend the bun binary path to the system PATH, in order to make it easier for other gems and utilities to "see" the existing bun executable without the need to monkey-patch tools that already support Bun. This approach only works when the bundlebun gem is already loaded, which is not always the case, unfortunately.
Class Method Summary collapse
-
.path ⇒ String
Returns the current system PATH.
-
.path=(new_path) ⇒ Object
Sets the system PATH to a new value (not prepends the value).
-
.prepend(new_path) ⇒ String
Prepends a new path to the system PATH.
-
.separator ⇒ String
The
PATH
separator for the current platform (:
or;
).
Class Method Details
.path ⇒ String
Returns the current system PATH.
15 16 17 |
# File 'lib/bundlebun/env_path.rb', line 15 def path ENV['PATH'] end |
.path=(new_path) ⇒ Object
Sets the system PATH to a new value (not prepends the value).
22 23 24 |
# File 'lib/bundlebun/env_path.rb', line 22 def path=(new_path) ENV['PATH'] = new_path end |
.prepend(new_path) ⇒ String
Prepends a new path to the system PATH. Makes sure to use different separators for different platforms.
31 32 33 34 35 36 37 38 39 |
# File 'lib/bundlebun/env_path.rb', line 31 def prepend(new_path) return if new_path.nil? || new_path.empty? path_to_check = Bundlebun::Platform.windows? ? path.downcase : path check_path = Bundlebun::Platform.windows? ? new_path.downcase : new_path self.path = "#{new_path}#{separator}#{path}" unless path_to_check.start_with?(check_path) path end |