jam-cloud/ruby/lib/jam_ruby/models/generic_state.rb

28 lines
1.1 KiB
Ruby

module JamRuby
class GenericState < ActiveRecord::Base
self.table_name = 'generic_state'
validates :env, :inclusion => {:in => ['development', 'staging', 'production', 'test']}
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.singleton
GenericState.find('default')
end
end
end