1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Get everyone running on Rails.env and fix the broken environment settings for script/console and script/dbconsole

This commit is contained in:
David Heinemeier Hansson 2010-01-11 14:01:28 -08:00
parent a9eebde856
commit 8cb594a2e1
11 changed files with 35 additions and 26 deletions

View file

@ -29,8 +29,6 @@ else
Encoding.default_external = Encoding::UTF_8
end
RAILS_ENV = (ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development").dup unless defined?(RAILS_ENV)
module Rails
autoload :Bootstrap, 'rails/bootstrap'
@ -86,7 +84,7 @@ module Rails
end
def env
@_env ||= ActiveSupport::StringInquirer.new(RAILS_ENV)
@_env ||= ActiveSupport::StringInquirer.new(ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development")
end
def cache

View file

@ -38,6 +38,11 @@ module Rails
config.load_once_paths.freeze
end
# TODO: Wrap in deprecation warning, everyone should be using Rails.env now
initializer :set_rails_env do
silence_warnings { Object.const_set "RAILS_ENV", Rails.env }
end
# Create tmp directories
initializer :ensure_tmp_directories_exist do
%w(cache pids sessions sockets).each do |dir_to_make|
@ -71,7 +76,7 @@ module Rails
begin
logger = ActiveSupport::BufferedLogger.new(config.log_path)
logger.level = ActiveSupport::BufferedLogger.const_get(config.log_level.to_s.upcase)
if RAILS_ENV == "production"
if Rails.env.production?
logger.auto_flushing = false
end
rescue StandardError => e

View file

@ -4,8 +4,6 @@ require "irb/completion"
module Rails
class Console
ENVIRONMENTS = %w(production development test)
def self.start(app)
new(app).start
end
@ -25,10 +23,6 @@ module Rails
opt.parse!(ARGV)
end
if env = ARGV.pop
ENV['RAILS_ENV'] = ENVIRONMENTS.find { |e| e.index(env) } || env
end
@app.initialize!
require "rails/console_app"
require "rails/console_sandbox" if options[:sandbox]
@ -54,3 +48,8 @@ module Rails
end
end
end
# Has to set the RAILS_ENV before config/application is required
if ARGV.first && !ARGV.first.index("-") && env = ARGV.pop # has to pop the env ARGV so IRB doesn't freak
ENV['RAILS_ENV'] = %w(production development test).find { |e| e.index(env) } || env
end

View file

@ -34,7 +34,6 @@ module Rails
abort opt.to_s unless (0..1).include?(ARGV.size)
end
env = ARGV.first || ENV['RAILS_ENV'] || 'development'
unless config = YAML::load(ERB.new(IO.read("#{@app.root}/config/database.yml")).result)[env]
abort "No database is configured for the environment '#{env}'"
end
@ -97,4 +96,9 @@ module Rails
end
end
end
end
# Has to set the RAILS_ENV before config/application is required
if ARGV.first && !ARGV.first.index("-") && env = ARGV.first
ENV['RAILS_ENV'] = %w(production development test).find { |e| e.index(env) } || env
end

View file

@ -34,7 +34,6 @@ end
ARGV.delete(code_or_file)
ENV["RAILS_ENV"] = options[:environment]
RAILS_ENV.replace(options[:environment]) if defined?(RAILS_ENV)
begin
if code_or_file.nil?

View file

@ -38,15 +38,14 @@ module Rails
end
def start
ENV["RAILS_ENV"] = options[:environment]
puts "=> Booting #{ActiveSupport::Inflector.demodulize(server)}"
puts "=> Rails #{Rails.version} application starting on http://#{options[:Host]}:#{options[:Port]}"
puts "=> Rails #{Rails.version} application starting in #{Rails.env} on http://#{options[:Host]}:#{options[:Port]}"
puts "=> Call with -d to detach" unless options[:daemonize]
trap(:INT) { exit }
puts "=> Ctrl-C to shutdown server" unless options[:daemonize]
ENV["RAILS_ENV"] = options[:environment]
RAILS_ENV.replace(options[:environment]) if defined?(RAILS_ENV)
super
ensure
puts 'Exiting' unless options[:daemonize]

View file

@ -129,7 +129,7 @@ module Rails
paths.tmp.cache "tmp/cache"
paths.config "config"
paths.config.locales "config/locales"
paths.config.environments "config/environments", :glob => "#{RAILS_ENV}.rb"
paths.config.environments "config/environments", :glob => "#{Rails.env}.rb"
paths
end
end
@ -212,7 +212,7 @@ module Rails
paths = []
# Add the old mock paths only if the directories exists
paths.concat(Dir["#{root}/test/mocks/#{RAILS_ENV}"]) if File.exists?("#{root}/test/mocks/#{RAILS_ENV}")
paths.concat(Dir["#{root}/test/mocks/#{Rails.env}"]) if File.exists?("#{root}/test/mocks/#{Rails.env}")
# Add the app's controller directory
paths.concat(Dir["#{root}/app/controllers/"])
@ -235,15 +235,15 @@ module Rails
def builtin_directories
# Include builtins only in the development environment.
(RAILS_ENV == 'development') ? Dir["#{RAILTIES_PATH}/builtin/*/"] : []
Rails.env.development? ? Dir["#{RAILTIES_PATH}/builtin/*/"] : []
end
def log_path
@log_path ||= File.join(root, 'log', "#{RAILS_ENV}.log")
@log_path ||= File.join(root, 'log', "#{Rails.env}.log")
end
def log_level
@log_level ||= RAILS_ENV == 'production' ? :info : :debug
@log_level ||= Rails.env.production? ? :info : :debug
end
def time_zone
@ -265,7 +265,7 @@ module Rails
end
def environment_path
"#{root}/config/environments/#{RAILS_ENV}.rb"
"#{root}/config/environments/#{Rails.env}.rb"
end
# Holds generators configuration:

View file

@ -1,3 +1,5 @@
require File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
require 'rails/commands/console'
require File.expand_path('../../config/application', __FILE__)
Rails::Console.start(<%= app_const %>.instance)

View file

@ -1,3 +1,5 @@
require File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
require 'rails/commands/dbconsole'
require File.expand_path('../../config/application', __FILE__)
Rails::DBConsole.start(<%= app_const %>.instance)

View file

@ -1,2 +1,3 @@
require File.expand_path('../../config/environment', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
require 'rails/commands/runner'
require File.expand_path('../../config/environment', __FILE__)

View file

@ -1,6 +1,6 @@
# Make double-sure the RAILS_ENV is set to test,
# so fixtures are loaded to the right database
silence_warnings { RAILS_ENV = "test" }
exit("Abort testing: Your Rails environment is not running in test mode!") unless Rails.env.test?
require 'test/unit'
require 'active_support/core_ext/kernel/requires'