Class: SystemWrapper

Inherits:
Object show all
Defined in:
lib/ceedling/system_wrapper.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.windows?Boolean

static method for use in defaults

Returns:

  • (Boolean)


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_argsObject



28
29
30
# File 'lib/ceedling/system_wrapper.rb', line 28

def cmdline_args
  return ARGV
end

#constants_include?(item) ⇒ Boolean

Returns:

  • (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_successObject



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_pathsObject



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_nowObject



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

Returns:

  • (Boolean)


12
13
14
# File 'lib/ceedling/system_wrapper.rb', line 12

def windows?
  return SystemWrapper.windows?
end