Project

rack-when

0.0
No commit activity in last 3 years
No release in over 3 years
Simple gem to load rack middleware only in certain environments.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.1
~> 13.0
>= 0

Runtime

>= 0
 Project Readme

Rack::When

Build Status Code Climate

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

  1. Fork it
  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