Ever get frustrated dealing with files or directories in ruby? Maybe it's just me, but using File, Dir, FileUtils, Pathname, etc makes me queasy. So I wrote POW! to make life easier.
Git it here http://github.com/probablycorey/pow
or sudo gem install pow
Since path manipulation is kind of boring, I'll just give a few examples of how it's helped me. Consider this directory structure...
/tmp
/sub_dir
/deeper_dir
/extra_dir
file.txt
program
README
To open a directory
path =Pow("tmp")
Open a file
Pow(:tmp,:sub_dir,:file.txt) do |file|# All the stuff you usually do with an open file!
file.readend
# The / operator accepcts symbols, strings or other Pow objects
file = path /:subdir/ "file.txt"
# You can also use brackets to access paths
file = path[:subdir, "file.txt"]
Create nested directories
# Great for code generationPow("MOAR").createdoPow("sub_dir").createdoPow("info.txt").createdo |file|
file.puts "Here is the info you desired!"
endPow("README").create_filedo |file|
file.puts "I'm so glad you read this."
end# Creates directory structure/MOAR/sub_dir
info.txtREADME