Feedback on new Path Library

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!
 
S

Sharon Rosner

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.

Congrats. This looks very nice!

Sharon
 
P

p. Corey

What does this do that pathname2 doesn't do?

Well, Pow does have the nested directory structure creation, but other
than that they both seem to have similar abilities but with a
different style. To be honest, i didn't know pathname2 existed when I
started, so I wasn't trying to rain on anyones parade.

Corey
 
M

Marc Heiler

I believe these two competing products (hehe ;> ) demonstrate that the
current solutions for the various Pathname.new File FileUtils Dir and so
on are a little bit cumbersome (to use)
I think you can get the basename with File too or, with less typing than
with the Pathname representation?
 
E

Eric Hodel

I believe these two competing products (hehe ;> ) demonstrate that the
current solutions for the various Pathname.new File FileUtils Dir
and so
on are a little bit cumbersome (to use)
I think you can get the basename with File too or, with less typing
than
with the Pathname representation?

How is FileUtils cumbersome?

I find it easier than using sh due to FileUtils::Verbose and
FileUtils::DryRun. Replacing RubyGems' setup.rb with a tiny,
debuggable installer was incredibly easy using FileUtils and Dir.
 
P

p. Corey

I find it easier than using sh due to FileUtils::Verbose and
FileUtils::DryRun. Replacing RubyGems' setup.rb with a tiny,
debuggable installer was incredibly easy using FileUtils and Dir.
First off I totally agree with you here, the FileUtils::DryRun and
FileUtils::Verbose are very helpful over sh to do such things. And Pow
does nothing to emulate that great functionality.

How is FileUtils cumbersome?
Individual FileUtil commands are not cumbersome, but the combination
of them with other methods is. Rarely do I just need mv a predefined
path to a new predefined. First I have to build the src_path using a
combination of File.dirname and File.join, then I have to do the same
with the dest_path as well as mkdir_p'ing it to make sure path
hierarchy exists. When I find myself using FileUtils it usually
involves doing this with multiples files and multiple commands, that's
where it becomes cumbersome. FileUtils just emulates shell commands,
which are great on the command line but archaic compared to the rest
of ruby's syntax and style.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top