Module: Sprinkle::Verifiers::Environment
- Defined in:
- lib/sprinkle/verifiers/environment.rb
Overview
Environment Verifier
Contains a verifier to check environment variables
Example Usage
verify { has_environment_variable "PATH" }
verify { has_environment_variable "ProgramFiles", "C:\\Program Files" }
Instance Method Summary collapse
-
#environment_variable_contains(name, text) ⇒ Object
Checks to make sure the
environment variablecontains the given text. -
#has_environment_variable(name, value = nil) ⇒ Object
Checks to make sure the
environment variableexists or has a specific value.
Instance Method Details
#environment_variable_contains(name, text) ⇒ Object
Checks to make sure the environment variable contains the given text
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/sprinkle/verifiers/environment.rb', line 30 def environment_variable_contains(name, text) name, text = name.to_s, text.to_s if RUBY_PLATFORM =~ /win32/ # use set | findstr to avoid shell substitution, which does not appear to work reliably with Kernel.system command = "set #{name} | findstr /c:\"#{text}\"" command << ' > NUL 2>&1' unless logger.debug? else command = "echo $#{name} | grep '#{text}'" end @commands << command end |
#has_environment_variable(name, value = nil) ⇒ Object
Checks to make sure the environment variable exists or has a specific value
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/sprinkle/verifiers/environment.rb', line 16 def has_environment_variable(name, value = nil) name, value = name.to_s, value.to_s if RUBY_PLATFORM =~ /win32/ # use set | findstr to avoid shell substitution, which does not appear to work reliably with Kernel.system command = "set #{name} | findstr /c:\"#{name}=\"" command << " | findstr /r /c:\"^.*=#{Regexp.quote value}$\"" unless value.empty? command << ' > NUL 2>&1' unless logger.debug? else command = value.nil? ? "test -n $#{name}" : "test $#{name} == \"#{value}\"" end @commands << command end |