MultiDir
MultiDir allow libraries and frameworks to request paths in a semantic way. This allows administrators to define real paths in one global standardized way.
No more Rails.root.join *%w(tmp uploaded)
anymore. Give administrators the
freedom to link the temp directory to /tmp/myapp
or any other system
specific place by just using MultiDir.tmp.join 'uploaded'
.
Note: MultiDir as a library is still under development but the concept sounds nice.
Installation
Add this line to your application's Gemfile:
gem 'multi_dir'
And then execute:
$ bundle
Or install it yourself as:
$ gem install multi_dir
Usage
For All
MultiDir allows to define any semantic path your app, library or framework may need. By default the following paths are specified:
MultiDir.bin # => 'bin'
MultiDir.lib # => 'lib'
MultiDir.tmp # => 'tmp'
MultiDir.cache # => 'tmp/cache'
MultiDir.files # => 'files'
MultiDir.config # => 'config
For Administrators
MultiDir provides everything you need to integrate some hipster app into your well known and proven operating system structure. It allows you to specify which content should live where without manual patching every piece of code.
Create or edit dirs.yml
in the application root directory (or whereever
you're running the app) or specific the path using MULTI_DIR_CONFIG
env
variable with the following content:
paths:
tmp: /tmp/myapp-srv2
files: /mnt/nfs2/storage
cache: /var/cache/apps/myapp
log: /var/log/myapp
This file allows you to specify the base paths for the application.
For Developers
MultiDir makes you a developer loved by administrators as you given them the freedom to adjust you app or library according there needs. It also makes you happy reaching another stage of more semantic programming.
You can just use MultiDir like you've used Rails.root.join
in the past.
See the following examples:
# Request a specific file
MultiDir.cache.join *%(pdfgen page5.pdf) # => "cache/pdfgen/page5.pdf"
# Request a file with a temporary name
MultiDir.tmp.tempname ['basename', '.jpg'] # => "tmp/basename20130519-11982-tzda0r.jpg"
# Get list of files in a additional configurable directory
MultiDir.cache[:uploads].glob 'path/**', '*.zip' # This allows admins to
# configure a special path for :uploads
# that if not given will be placed in 'cache'.
# => ["/media/uploads/a/virus.zip", "/media/uploads/attachments/ppt.zip"]
You can even define your own new top level semantic path:
MultiDir::Paths.define :uploads, in: :tmp
This allows you to use uploads
as a top level path that will be placed in tmp
if not configured otherwise:
MultiDir.uploads.join 'abrng.pdf' # => "/tmp/uploads/abrng.pdf"
More features will follow.
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Add specs for your feature
- Implement your feature
- Check that all specs are passing
- Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
License
Copyright (c) 2013 Jan Graichen - MIT License