module JamRuby class GenericState < ActiveRecord::Base self.table_name = 'generic_state' validates :env, :inclusion => {:in => ['development', 'staging', 'production', 'test']} def self.env GenericState.singleton.env end def self.allow_emails? database_environment = singleton.env # if the database says we are in production/staging, then the config has to also agree and say we are in production/staging to send emails # this is to protect against developers loading a staging or production environment and possibly sending emails to # we even go one step further, and make sure ENV['BUILD_NUMBER'] is set, which is something you do in production, but would be very rare in development # or if your database says 'development' and config say 'development', then we allow emails to go out too (!ENV['BUILD_NUMBER'].nil? && (Environment.mode == 'production' || Environment.mode == 'staging') && (database_environment == 'production' || database_environment == 'staging')) || (database_environment == 'development' && Environment.mode == 'development') end def self.affiliate_tallied_at GenericState.singleton.affiliate_tallied_at end def self.singleton GenericState.find('default') end end end