file_wrapper.rb 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. require 'rubygems'
  2. require 'rake' # for FileList
  3. require 'fileutils'
  4. require 'ceedling/constants'
  5. class FileWrapper
  6. def get_expanded_path(path)
  7. return File.expand_path(path)
  8. end
  9. def basename(path, extension=nil)
  10. return File.basename(path, extension) if extension
  11. return File.basename(path)
  12. end
  13. def exist?(filepath)
  14. return true if (filepath == NULL_FILE_PATH)
  15. return File.exist?(filepath)
  16. end
  17. def directory?(path)
  18. return File.directory?(path)
  19. end
  20. def dirname(path)
  21. return File.dirname(path)
  22. end
  23. def directory_listing(glob)
  24. return Dir.glob(glob, File::FNM_PATHNAME)
  25. end
  26. def rm_f(filepath, options={})
  27. FileUtils.rm_f(filepath, options)
  28. end
  29. def rm_r(filepath, options={})
  30. FileUtils.rm_r(filepath, options={})
  31. end
  32. def cp(source, destination, options={})
  33. FileUtils.cp(source, destination, options)
  34. end
  35. def compare(from, to)
  36. return FileUtils.compare_file(from, to)
  37. end
  38. def open(filepath, flags)
  39. File.open(filepath, flags) do |file|
  40. yield(file)
  41. end
  42. end
  43. def read(filepath)
  44. return File.read(filepath)
  45. end
  46. def touch(filepath, options={})
  47. FileUtils.touch(filepath, options)
  48. end
  49. def write(filepath, contents, flags='w')
  50. File.open(filepath, flags) do |file|
  51. file.write(contents)
  52. end
  53. end
  54. def readlines(filepath)
  55. return File.readlines(filepath)
  56. end
  57. def instantiate_file_list(files=[])
  58. return FileList.new(files)
  59. end
  60. def mkdir(folder)
  61. return FileUtils.mkdir_p(folder)
  62. end
  63. end