2012-01-26 19:02:25 +00:00
|
|
|
$message_mutex = Mutex.new
|
|
|
|
def show_message message
|
|
|
|
$message_mutex.lock
|
|
|
|
puts message
|
|
|
|
$message_mutex.unlock
|
|
|
|
end
|
|
|
|
|
|
|
|
def error_and_exit text, exit_code = 2
|
|
|
|
show_message text
|
|
|
|
exit exit_code
|
|
|
|
end
|
|
|
|
|
2012-01-27 18:29:02 +00:00
|
|
|
def constantize camel_cased_word
|
|
|
|
names = camel_cased_word.split('::')
|
|
|
|
names.shift if names.empty? || names.first.empty?
|
|
|
|
|
|
|
|
constant = Object
|
|
|
|
names.each do |name|
|
|
|
|
constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
|
|
|
|
end
|
|
|
|
constant
|
|
|
|
end
|
|
|
|
|
2012-01-31 17:59:27 +00:00
|
|
|
def file_name_to_class_name file_name
|
|
|
|
"T_" + file_name.gsub(/^test-/, "").gsub(/\.rb$/, "")
|
|
|
|
end
|
|
|
|
|
|
|
|
def class_name_to_file_name class_name
|
|
|
|
class_name.gsub(/^T_/, "test-") + ".rb"
|
|
|
|
end
|
|
|
|
|
2012-01-27 18:29:02 +00:00
|
|
|
class Array
|
|
|
|
def extract_options!
|
|
|
|
last.is_a?(::Hash) ? pop : {}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-03-10 19:02:51 +00:00
|
|
|
class String
|
|
|
|
def md5
|
|
|
|
Digest::MD5.hexdigest self
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-01-27 18:29:02 +00:00
|
|
|
# install md5 handler
|
2021-07-06 11:54:23 +00:00
|
|
|
if $is_macos
|
2012-01-27 18:29:02 +00:00
|
|
|
def md5 name
|
|
|
|
`/sbin/md5 #{name}`.chomp.gsub(/.*=\s*/, "")
|
|
|
|
end
|
|
|
|
else
|
|
|
|
def md5 name
|
|
|
|
`md5sum #{name}`.chomp.gsub(/\s+.*/, "")
|
|
|
|
end
|
|
|
|
end
|
2021-07-06 11:36:58 +00:00
|
|
|
|
|
|
|
def run_bash command
|
|
|
|
return system command if !$is_windows
|
|
|
|
|
|
|
|
cmd_file = Tempfile.new
|
|
|
|
cmd_file.write command
|
|
|
|
cmd_file.close
|
|
|
|
|
|
|
|
FileUtils.chmod 0700, cmd_file.path
|
|
|
|
|
|
|
|
system "bash -c #{cmd_file.path}"
|
|
|
|
end
|