Class: SystemWrapper
Class Method Summary collapse
-
.windows? ⇒ Boolean
static method for use in defaults.
Instance Method Summary collapse
- #add_load_path(path) ⇒ Object
- #cmdline_args ⇒ Object
- #constants_include?(item) ⇒ Boolean
- #env_get(name) ⇒ Object
- #env_set(name, value) ⇒ Object
- #eval(string) ⇒ Object
- #module_eval(string) ⇒ Object
- #require_file(path) ⇒ Object
- #ruby_success ⇒ Object
- #search_paths ⇒ Object
- #shell_backticks(command, boom = true) ⇒ Object
- #shell_system(command, boom = true) ⇒ Object
- #time_now ⇒ Object
-
#windows? ⇒ Boolean
class method so as to be mockable for tests.
Class Method Details
.windows? ⇒ Boolean
static method for use in defaults
6 7 8 9 |
# File 'lib/ceedling/system_wrapper.rb', line 6 def self.windows? return ((RbConfig::CONFIG['host_os'] =~ /mswin|mingw/) ? true : false) if defined?(RbConfig) return ((Config::CONFIG['host_os'] =~ /mswin|mingw/) ? true : false) end |
Instance Method Details
#add_load_path(path) ⇒ Object
62 63 64 |
# File 'lib/ceedling/system_wrapper.rb', line 62 def add_load_path(path) $LOAD_PATH.unshift(path) end |
#cmdline_args ⇒ Object
28 29 30 |
# File 'lib/ceedling/system_wrapper.rb', line 28 def cmdline_args return ARGV end |
#constants_include?(item) ⇒ Boolean
75 76 77 78 |
# File 'lib/ceedling/system_wrapper.rb', line 75 def constants_include?(item) # forcing to strings provides consistency across Ruby versions return Object.constants.map{|constant| constant.to_s}.include?(item.to_s) end |
#env_get(name) ⇒ Object
36 37 38 |
# File 'lib/ceedling/system_wrapper.rb', line 36 def env_get(name) return ENV[name] end |
#env_set(name, value) ⇒ Object
32 33 34 |
# File 'lib/ceedling/system_wrapper.rb', line 32 def env_set(name, value) ENV[name] = value end |
#eval(string) ⇒ Object
20 21 22 |
# File 'lib/ceedling/system_wrapper.rb', line 20 def eval(string) return eval(string) end |
#module_eval(string) ⇒ Object
16 17 18 |
# File 'lib/ceedling/system_wrapper.rb', line 16 def module_eval(string) return Object.module_eval("\"" + string + "\"") end |
#require_file(path) ⇒ Object
66 67 68 |
# File 'lib/ceedling/system_wrapper.rb', line 66 def require_file(path) require(path) end |
#ruby_success ⇒ Object
70 71 72 73 |
# File 'lib/ceedling/system_wrapper.rb', line 70 def ruby_success # We are successful if we've never had an exit code that went boom (either because it's empty or it was 0) return ($exit_code.nil? || ($exit_code == 0)) && ($!.nil? || $!.is_a?(SystemExit) && $!.success?) end |
#search_paths ⇒ Object
24 25 26 |
# File 'lib/ceedling/system_wrapper.rb', line 24 def search_paths return ENV['PATH'].split(File::PATH_SEPARATOR) end |
#shell_backticks(command, boom = true) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/ceedling/system_wrapper.rb', line 44 def shell_backticks(command, boom = true) retval = `#{command}`.freeze $exit_code = ($?.exitstatus).freeze if boom return { :output => retval.freeze, :exit_code => ($?.exitstatus).freeze } end |
#shell_system(command, boom = true) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/ceedling/system_wrapper.rb', line 53 def shell_system(command, boom = true) system( command ) $exit_code = ($?.exitstatus).freeze if boom return { :output => "".freeze, :exit_code => ($?.exitstatus).freeze } end |
#time_now ⇒ Object
40 41 42 |
# File 'lib/ceedling/system_wrapper.rb', line 40 def time_now return Time.now.asctime end |
#windows? ⇒ Boolean
class method so as to be mockable for tests
12 13 14 |
# File 'lib/ceedling/system_wrapper.rb', line 12 def windows? return SystemWrapper.windows? end |