No commit activity in last 3 years
No release in over 3 years
Eliminate silent errors in Rails environment detection due to typos.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

rails_environment

Gem Version Build Status Code Climate Coverage Status

Error-free convenience methods for determining the running Rails environment.

This gem enables code like:

if RailsEnvironment.production?
   <do_production_only_stuff>
end

This prevents typos like:

if Rails.env == 'productoin' ...
if Rails.env.productoin? ...

So we get a runtime error if we misspell an environment instead of a silent bug.

Available methods

For standard Rails applications with development, test and production environments you get:

Predicate method for each environment

  • RailsEnvironment.development?
  • RailsEnvironment.test?
  • RailsEnvironment.production?

Negated predicate methods

  • RailsEnvironment.not_development?
  • RailsEnvironment.not_test?
  • RailsEnvironment.not_production?

You can also "or" the environments, and negate the "or"'s

  • RailsEnvironment.test_or_production?
  • RailsEnvironment.not_test_or_production?
  • etc.

Short and Long environment names

RailsEnvironment.short  #=> 'DEV'
RailsEnvironment.long   #=> 'Development'

# customize the short/long names
RailsEnvironment.environment_strings['development']['short'] = 'DVL'
RailsEnvironment.short  #=> 'DVL'

Notes

  • The methods available are based on the actual environments, i.e., ../config/environments/*.rb
  • If you add/remove a file in ../config/environments you will need to restart your server