module System
Provides utilities for converting environment values to shell-compatible strings.
Definitions
def self.shell_escape(value)
Escape a value for safe use in a shell command string.
Signature
-
parameter
valueString | Array The value to escape.
-
returns
String The shell-escaped string.
Implementation
def self.shell_escape(value)
case value
when Array
value.flatten.collect{|argument| shell_escape(argument)}.join(" ")
else
# Ensure that any whitespace has been escaped:
value.to_s.gsub(/ /, '\ ')
end
end
def self.valid_for_export(value)
Check whether a value is suitable for export to a shell environment.
Signature
-
parameter
valueObject The value to check.
-
returns
Boolean trueif the value can be exported,falseotherwise.
Implementation
def self.valid_for_export(value)
case value
when Array
true
when Symbol
false
when Proc
false
when Default
false
when Replace
false
when Define
false
else
true
end
end
def self.convert_to_shell(environment)
Convert an environment to a shell-compatible hash with uppercase string keys and escaped string values.
Signature
-
parameter
environmentEnvironment The environment to convert.
-
returns
Hash A hash of uppercase string keys mapped to shell-escaped string values.
Implementation
def self.convert_to_shell(environment)
values = environment.values.select{|key, value| valid_for_export(value)}
Hash[values.map{|key, value| [
key.to_s.upcase,
shell_escape(value)
]}]
end