tl;dr always stay up-to-date if you want life to be easy
I hear rails 5.0 is coming out soon. That's exciting. The news reminded me of a time recently when I wanted to use some environment variables to separate the environments I would log to fluentd and those I would log to a temporary log file. So I figured there was some kind of configuration I could put in each of the environment configuration files (i.e. in config/environments/), that was similar to defining environment variables in your bashrc. I wanted something easy like config. fluent_logging = true in the production environment and config.fluent_logging = false in the test environment. Then maybe I'd be able to call it with if Rails.fluent_logging ...
Turns out it is this easy... If you have rails 4.2 and up. But the project I was working on was clearly several decades behind, because we were at 4.1.2, and the function isn't included. For those of you who keep up with the cool kids, it's actually as easy as this:
config.x.fluent_logging = true # in your config/environments/ files
if Rails.configuration.x.super_debugger... # in any file where you wanna check something based on environment
Now of course you could also just do the whole if Rails.env == 'test' || Rails.env == 'development'... but what if you change your mind and have to go through every file where you log and change the if statement? With these kind of pseudo environment variables, life is easy! For the golden oldies, it requires a little more configuration. But, it's not impossible.
The implementation for old rails versions is actually very similar, but I like that the new rails versions have this functionality built in.
config.fluent = ActiveSupport::OrderedOptions.new
config.fluent.logging = false # in your config/environments/ files
if Rails.configuration.fluent.logging... # in any file where you'd like to check this variable
ActiveSupport::OrderedOptions lets you basically define key value pairs without needing a hash. Any instance of ActiveSupport::OrderedOptions responds to any methods and lets you define what those methods should return. So I've created an instance of it that I call "config.fluent", so I can define config.fluent.logging to be false. You can also define config.fluent.my_favorite_number = 56 and when you call Rails.configuration.fluent.my_favorite_number it will return 56. Pretty cool, eh?
Still, I like keeping up with new upgrades. The world of open source moves pretty fast. If you don't stop and look around once in a while, you just might miss it. :)