Feedback on new Path Library

Discussion in 'Ruby' started by p. Corey, Oct 11, 2007.

  1. p. Corey

    p. Corey Guest

    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!
    p. Corey, Oct 11, 2007
    #1
    1. Advertising

  2. On Oct 11, 6:30 pm, "p. Corey" <> wrote:
    > 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
    Sharon Rosner, Oct 11, 2007
    #2
    1. Advertising

  3. On Oct 11, 10:30 am, "p. Corey" <> wrote:
    > 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.


    What does this do that pathname2 doesn't do?

    http://raa.ruby-lang.org/project/pathname2

    Regards,

    Dan
    Daniel Berger, Oct 11, 2007
    #3
  4. p. Corey

    p. Corey Guest

    > 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
    p. Corey, Oct 12, 2007
    #4
  5. p. Corey

    Marc Heiler Guest

    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?
    --
    Posted via http://www.ruby-forum.com/.
    Marc Heiler, Oct 12, 2007
    #5
  6. p. Corey

    Eric Hodel Guest

    On Oct 11, 2007, at 17:26 , Marc Heiler wrote:
    > 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.

    --
    Poor workers blame their tools. Good workers build better tools. The
    best workers get their tools to do the work for them. -- Syndicate Wars
    Eric Hodel, Oct 12, 2007
    #6
  7. p. Corey

    p. Corey Guest

    > 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.
    p. Corey, Oct 12, 2007
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeff Wagner

    sys.path.append('/my/new/path')

    Jeff Wagner, Nov 24, 2003, in forum: Python
    Replies:
    3
    Views:
    518
    Patrick Useldinger
    Nov 24, 2003
  2. Ron Adam
    Replies:
    3
    Views:
    433
    Ron Adam
    Aug 2, 2005
  3. Terracotta

    library.path VS class.path

    Terracotta, Jul 16, 2007, in forum: Java
    Replies:
    1
    Views:
    888
    Gordon Beaton
    Jul 16, 2007
  4. Terracotta

    library.path VS class.path

    Terracotta, Jul 16, 2007, in forum: Java
    Replies:
    0
    Views:
    455
    Terracotta
    Jul 16, 2007
  5. Ulf Åström

    Serialization library, request for feedback

    Ulf Åström, Dec 13, 2012, in forum: C Programming
    Replies:
    42
    Views:
    553
Loading...

Share This Page