Skip to content

Instantly share code, notes, and snippets.

@caleon
Created August 29, 2011 12:20
Show Gist options
  • Save caleon/1178288 to your computer and use it in GitHub Desktop.
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.
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