Rack::When
Shortcut handler for performing tasks in specific environments. Specific
environments can be set to run specific sections of code. I wrote this
to handle rack-middleware and as such it works in a config.ru
but you
could use it to run anything.
The order of precedence for env is ENV['RACK_ENV']
or ENV['RAILS_ENV']
but it defaults to development
.
Usage
In your config.ru
do
Rack::When.development do
# Things you want done in development
use DevelopmentMiddleware
end
Rack::When.production do
# Things you want done in production
use ProductionMetricMaker
end
run MyApplication
You can also specify the enviroment directly if you would prefer:
Rack::When.environments :custom_env do
# My custom env code
end
and with multiple environments:
Rack::When.environments :custom_env, :another_custom_env do
# My custom env code
end
Installation
Add this line to your application's Gemfile:
gem 'rack-when'
And then execute:
$ bundle
Or install it yourself as:
$ gem install rack-when
Contributing
- Fork it
- 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 new Pull Request