2014-11-06 06:07:16 -05:00
|
|
|
module Gitlab
|
|
|
|
module Utils
|
|
|
|
extend self
|
|
|
|
|
|
|
|
# Run system command without outputting to stdout.
|
|
|
|
#
|
|
|
|
# @param cmd [Array<String>]
|
2014-11-06 04:47:38 -05:00
|
|
|
# @return [Boolean]
|
2014-11-06 06:07:16 -05:00
|
|
|
def system_silent(cmd)
|
2016-08-15 09:32:36 -04:00
|
|
|
Popen.popen(cmd).last.zero?
|
2014-11-06 06:07:16 -05:00
|
|
|
end
|
2015-05-02 17:43:46 -04:00
|
|
|
|
|
|
|
def force_utf8(str)
|
|
|
|
str.force_encoding(Encoding::UTF_8)
|
|
|
|
end
|
2016-10-28 16:56:13 -04:00
|
|
|
|
|
|
|
def to_boolean(value)
|
|
|
|
return value if [true, false].include?(value)
|
|
|
|
return true if value =~ /^(true|t|yes|y|1|on)$/i
|
|
|
|
return false if value =~ /^(false|f|no|n|0|off)$/i
|
|
|
|
|
|
|
|
nil
|
|
|
|
end
|
2017-05-25 07:31:21 -04:00
|
|
|
|
|
|
|
def boolean_to_yes_no(bool)
|
|
|
|
if bool
|
|
|
|
'Yes'
|
|
|
|
else
|
|
|
|
'No'
|
|
|
|
end
|
|
|
|
end
|
2014-11-06 06:07:16 -05:00
|
|
|
end
|
|
|
|
end
|