Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

filetree

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

filetree

  • 1.0.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

FileTree

A simple tree structure for working with FilePath objects in ruby. I simply took the simple_tree module from https://github.com/ealdent/simple-tree and hacked it into Pathname from the std-lib. This means you get all the awesome features of working with Pathname, as well as making it easy to examine a filepath's ancestors and descendants.

Usage

Install

install with: gem install filetree

Examples


    require "filetree"

    tree = FileTree.new('/home/user/test/test1/test2')
    # => #<FileTree:/home/user/test/test1/test2>

    tree.parent
    # => #<FileTree:/home/user/test/test1>

    tree.ancestors
    # => [#<FileTree:/home/user/test>,
    #     #<FileTree:/home/user>,
    #     #<FileTree:/home>,
    #     #<FileTree:/>]

    tree.descendants
    # => [#<FileTree:/home/user/test/test1/test2/testee>,
    #     #<FileTree:/home/user/test/test1/test2/testee/testeggg>,
    #     #<FileTree:/home/user/test/test1/test2/testee/testeggg/test4>,
    #     #<FileTree:/home/user/test/test1/test2/testee/testeggg/test4/myfile.txt>,
    #     #<FileTree:/home/user/test/test1/test2/testee/testeggg/test3>,
    #     #<FileTree:/home/user/test/test1/test2/testee/testeggg/test3/no>,
    #     #<FileTree:/home/user/test/test1/test2/testee/test4>,
    #     #<FileTree:/home/user/test/test1/test2/testee/test4/myfile.txt>,
    #     #<FileTree:/home/user/test/test1/test2/testee/test3>,
    #     #<FileTree:/home/user/test/test1/test2/testee/test3/no>]

    des_arr = tree.descendants.map { |e| FileTree.new(e.relative_path_from(FileTree.new('/home/user'))) }
    # => [#<FileTree:test/test1/test2/testee>,
    #     #<FileTree:test/test1/test2/testee/testeggg>,
    #     #<FileTree:test/test1/test2/testee/testeggg/test4>,
    #     #<FileTree:test/test1/test2/testee/testeggg/test4/myfile.txt>,
    #     #<FileTree:test/test1/test2/testee/testeggg/test3>,
    #     #<FileTree:test/test1/test2/testee/testeggg/test3/no>,
    #     #<FileTree:test/test1/test2/testee/test4>,
    #     #<FileTree:test/test1/test2/testee/test4/myfile.txt>,
    #     #<FileTree:test/test1/test2/testee/test3>,
    #     #<FileTree:test/test1/test2/testee/test3/no>]

    des_arr.first
    # => #<FileTree:test/test1/test2/testee>

    des_arr.last.ancestors # infinite loop. "ancestors" depends on hitting "/" to stop.

    # the "tree_rep" method provides prettyprinting for creating your own to_s methods
    puts tree.tree_rep
    # => nil

    # >> #<FileTree:/home/user/test/test1/test2>
    # >>  \- #<FileTree:/home/user/test/test1/test2/testee>
    # >>      \- #<FileTree:/home/user/test/test1/test2/testee/testeggg>
    # >>      |    \- #<FileTree:/home/user/test/test1/test2/testee/testeggg/test4>
    # >>      |    |    \- #<FileTree:/home/user/test/test1/test2/testee/testeggg/test4/myfile.txt>
    # >>      |    \- #<FileTree:/home/user/test/test1/test2/testee/testeggg/test3>
    # >>      |    |    \- #<FileTree:/home/user/test/test1/test2/testee/testeggg/test3/no>
    # >>      \- #<FileTree:/home/user/test/test1/test2/testee/test4>
    # >>      |    \- #<FileTree:/home/user/test/test1/test2/testee/test4/myfile.txt>
    # >>      \- #<FileTree:/home/user/test/test1/test2/testee/test3>
    # >>      |    \- #<FileTree:/home/user/test/test1/test2/testee/test3/no>

Documentation

View the docs.

Credits

All credit belongs to the following persons, I just cobbled this together from their work:

  • @ealdent
  • The authors and maintainers of Pathname

License

Distributed under the BSD license, please see LICENSE for more information.

FAQs

Package last updated on 16 May 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc