module FileTest module_function # Return a cached list of the PATH environment variable. # This is a support method used by #bin? def command_paths @command_paths ||= ENV['PATH'].split(/[:;]/) end # Is a file a command executable? # # TODO: Make more robust. Probably needs to be fixed for Windows. def bin?(fname) is_bin = command_paths.any? do |f| FileTest.exist?(File.join(f, fname)) end #is_bin ? File.basename(fname) : false is_bin ? fname : false end # Is a path considered reasonably "safe"? # # TODO: Make more robust. def safe?(path) case path when *[ '/', '/*', '/**/*' ] return false end true end # Does a path need updating, based on given +sources+? # This compares mtimes of give paths. Returns false # if the path needs to be updated. def out_of_date?(path, *sources) return true unless File.exist?(path) sources = sources.collect{ |source| Dir.glob(source) }.flatten mtimes = sources.collect{ |file| File.mtime(file) } return true if mtimes.empty? # TODO: This the way to go here? File.mtime(path) < mtimes.max end end