file.rb 620 B

12345678910111213141516171819202122232425
  1. class Chef
  2. class Resource
  3. class File
  4. def include?(str)
  5. return false unless ::File.exists?(@path)
  6. file_content = IO.read @path
  7. if file_content =~ /#{str}/
  8. Chef::Log.info("file[#{@path}] contains the string '#{str}'")
  9. true
  10. else
  11. Chef::Log.info("file[#{@path}] doesn't contains the string '#{str}'")
  12. false
  13. end
  14. end
  15. def replace(str, str2)
  16. Chef::Log.info("replacing '#{str}' with '#{str2}' at #{@path}")
  17. old_content = IO.read @path
  18. content old_content.gsub(str, str2)
  19. end
  20. end
  21. end
  22. end