A simple class to handle conditional logic of looking for a file in multiple paths.
Add this line to your application's Gemfile:
gem 'path_to'
And then execute:
$ bundle
Or install it yourself as:
$ gem install path_to
Not unlike a $PATH
environment variables, a PathTo
instance contains one
or more locations to look for a file, and will return the first file it finds.
Example:
Suppose you have some files in the following directory structure:
├── default_files
│ └── alpha
│ └── bravo
├── specific_files
│ └── alpha
Then you can use path_to
to add specific_files
and default_files
to the
locations to look for your files.
require 'path_to'
p = PathTo.new('specific_files', 'default_files')
p.path_to 'alpha'
# => 'specific_files/alpha'
p.path_to 'bravo'
# => 'default_files/bravo'
And there is a shortcut for returning File
objects.
p.file('alpha')
# => #<File:specific_files/alpha>
After checking out the repo, run bin/setup
to install dependencies. Then, run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
to create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
- Fork it ( https://github.com/[my-github-username]/path_to/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request