Created
August 29, 2011 12:20
-
-
Save caleon/1178288 to your computer and use it in GitHub Desktop.
An extension of ActiveSupport::StringInquirer to have a grouping of environments such that Rails.env.live? checks if the environment is either production OR staging, and Rails.env.trial? to check that the env is neither of those.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RailsEnvInquirer < ActiveSupport::StringInquirer | |
def live? | |
%w(production staging).include?(self) | |
end | |
def trial? | |
!live? | |
end | |
def grouping | |
live? ? "live" : "trial" | |
end | |
end | |
module Rails | |
class << self | |
def env_with_groupings | |
@_env = nil unless @_env.is_a?(RailsEnvInquirer) | |
@_env ||= RailsEnvInquirer.new(ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development") | |
end | |
alias_method_chain :env, :groupings | |
def env_with_groupings=(environment) | |
@_env = nil unless @_env.is_a?(RailsEnvInquirer) | |
@_env ||= RailsEnvInquirer.new(environment) | |
end | |
alias_method_chain :env=, :groupings | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment