class Object
Public Instance Methods
cap_first()
click to toggle source
# File lib/externals/extensions/string.rb, line 2 def cap_first "#{self[0].chr.upcase}#{self[1..(self.length - 1)]}" end
classify()
click to toggle source
# File lib/externals/extensions/string.rb, line 6 def classify split('_').map(&:cap_first).join end
cp_a(source, dest, options = {})
click to toggle source
simulates cp -a
# File lib/externals/extensions/file_utils.rb, line 5 def cp_a source, dest, options = {} cp_r source, dest, options.merge(:preserve => true) end
dir_empty?(path)
click to toggle source
# File lib/externals/extensions/file_utils.rb, line 54 def dir_empty? path File.directory?(path) && File.exist?(path) && !Dir.entries(path).detect{|entry| !["..","."].include?(entry)} end
lines_by_width(width = 32)
click to toggle source
# File lib/externals/extensions/string.rb, line 12 def lines_by_width(width = 32) width ||= 32 lines = [] string = gsub(/\s+/, ' ') while string.size > 0 if string.size <= width lines << string string = "" else index = string[0, width + 1].rindex(/\s/) unless index # let's find the first space we can. index = string.index(/\s/) end if index lines << string[0, index] string = string[(index + 1)..-1] else lines << string string = "" end end end lines end
rm_rf(*args)
click to toggle source
going to try to give a delay after calling rm if necessary…
# File lib/externals/extensions/file_utils.rb, line 26 def rm_rf *args tries = 0 rm = proc do rm_rf_old(*args) while File.exist?(args[0]) && tries < 10 # :nocov: sleep 1 tries += 1 # :nocov: end end rm.call if tries >= 10 # :nocov: puts "WARNING: deleted #{args[0]} didn't work, trying again" tries = 0 rm.call if tries >= 10 raise "Could not delete #{args[0]}" end # :nocov: end end
Also aliased as: rm_rf_old
rm_rf_ie(file, options = {})
click to toggle source
calls rm_rf
if the file exists
# File lib/externals/extensions/file_utils.rb, line 10 def rm_rf_ie file, options = {} rm_rf file, options if File.exist?(file) end
rmdir_ie(path)
click to toggle source
calls rmdir if the file exists
# File lib/externals/extensions/file_utils.rb, line 20 def rmdir_ie path rmdir path if File.exist?(path) end
rmdir_if_empty_ie(path)
click to toggle source
calls rmdir if the file exists and is empty
# File lib/externals/extensions/file_utils.rb, line 15 def rmdir_if_empty_ie path rmdir path if File.exist?(path) && dir_empty?(path) end