Coder Social home page Coder Social logo

homecoming's Introduction

Homecoming

Build Status

Homecoming let's you easily traverse all parent directories of a given or the current directory.

This comes in handy when searching for a config file with settings that can be overridden by the same config file in a lower level directory (a popular example being .gitignore).

Installation

Add this line to your application's Gemfile:

gem 'homecoming'

And then execute:

$ bundle

Or install it yourself as:

$ gem install homecoming

Usage

Finding files

Homecoming.find searches for a given filename in the current and all parent directories.

# Given the following directory structure:

/
  home/
    rrrene/
      projects/
        your_project/
          .yourconfig
      .yourconfig

Homecoming.find(".yourconfig", "/home/rrrene/projects/your_project")
# => ["/home/rrrene/.yourconfig",
      "/home/rrrene/projects/your_project/.yourconfig"]

If no path is given as second parameter, the current directory is the starting point of the traversal.

Traversing parents

Homecoming.each traverses and yields the given and all parent directories.

Homecoming.each("/home/rrrene/projects/your_project") do |dir|
  # ...
end

If no path is given, the current directory is the starting point of the traversal.

In our example, this would yield the following directories beginning with the given/current one:

"/home/rrrene/projects/your_project"
"/home/rrrene/projects"
"/home/rrrene"
"/home"
"/"

Contributing

  1. Fork it ( http://github.com/rrrene/homecoming/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Author

René Föhring (@rrrene)

License

Homecoming is released under the MIT License. See the LICENSE.txt file for further details.

homecoming's People

Contributors

rrrene avatar

Stargazers

Chris Olstrom avatar Angus H. avatar  avatar Peter Leitzen avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.