P
p. Corey
I created a new Path library (http://pow.rubyforge.org) that combines
a lot of the functionality of Dir, FileUtils, File and Pathname into
one with a object centered approach. I'm looking for some feedback to
see if people would find this useful, or if I am the only one that get
frustrated when trying to deal with paths in ruby.
Here are some quick example of how it makes things easier...
File.read(File.join(DIR_CONSTANT, "some_text.txt"))
you be written as
Pow[DIR_CONSTANT, "some_text.txt].read
Or if you wanted to to find the number of files in each sub directory
Pathname.new("/usr/lib/ruby/1.8").children(true).select {|p|
p.directory?}.collect {|d| d.children.length}
you would do
Pow["/usr/lib/ruby/1.8"].directories.collect {|d| d.files.length}
Also if you want to create a nested directory structure you can easily
do that.
Pow["./moar"].create do
Pow["empty_dir"].create
Pow["sub_dir"].create do
Pow["info.txt"].create {|file| file.puts "Here is the info you
desired!"}
end
end
would create...
/moar
/empty_dir
/sub_dir
info.txt
It is still a work in progress so any feedback would be great! I
realize this is all just syntactic sugar, but i find it much easier
than using bits of File, Dir, FileUtils and Pathname all over the
place.
Corey
P.S. Why did I call it Pow? Because it was quick to type and all other
path-type names were taken!
a lot of the functionality of Dir, FileUtils, File and Pathname into
one with a object centered approach. I'm looking for some feedback to
see if people would find this useful, or if I am the only one that get
frustrated when trying to deal with paths in ruby.
Here are some quick example of how it makes things easier...
File.read(File.join(DIR_CONSTANT, "some_text.txt"))
you be written as
Pow[DIR_CONSTANT, "some_text.txt].read
Or if you wanted to to find the number of files in each sub directory
Pathname.new("/usr/lib/ruby/1.8").children(true).select {|p|
p.directory?}.collect {|d| d.children.length}
you would do
Pow["/usr/lib/ruby/1.8"].directories.collect {|d| d.files.length}
Also if you want to create a nested directory structure you can easily
do that.
Pow["./moar"].create do
Pow["empty_dir"].create
Pow["sub_dir"].create do
Pow["info.txt"].create {|file| file.puts "Here is the info you
desired!"}
end
end
would create...
/moar
/empty_dir
/sub_dir
info.txt
It is still a work in progress so any feedback would be great! I
realize this is all just syntactic sugar, but i find it much easier
than using bits of File, Dir, FileUtils and Pathname all over the
place.
Corey
P.S. Why did I call it Pow? Because it was quick to type and all other
path-type names were taken!