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:
parent
a9eebde856
commit
8cb594a2e1
11 changed files with 35 additions and 26 deletions
|
@ -29,8 +29,6 @@ else
|
||||||
Encoding.default_external = Encoding::UTF_8
|
Encoding.default_external = Encoding::UTF_8
|
||||||
end
|
end
|
||||||
|
|
||||||
RAILS_ENV = (ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development").dup unless defined?(RAILS_ENV)
|
|
||||||
|
|
||||||
module Rails
|
module Rails
|
||||||
autoload :Bootstrap, 'rails/bootstrap'
|
autoload :Bootstrap, 'rails/bootstrap'
|
||||||
|
|
||||||
|
@ -86,7 +84,7 @@ module Rails
|
||||||
end
|
end
|
||||||
|
|
||||||
def env
|
def env
|
||||||
@_env ||= ActiveSupport::StringInquirer.new(RAILS_ENV)
|
@_env ||= ActiveSupport::StringInquirer.new(ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development")
|
||||||
end
|
end
|
||||||
|
|
||||||
def cache
|
def cache
|
||||||
|
|
|
@ -38,6 +38,11 @@ module Rails
|
||||||
config.load_once_paths.freeze
|
config.load_once_paths.freeze
|
||||||
end
|
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
|
# Create tmp directories
|
||||||
initializer :ensure_tmp_directories_exist do
|
initializer :ensure_tmp_directories_exist do
|
||||||
%w(cache pids sessions sockets).each do |dir_to_make|
|
%w(cache pids sessions sockets).each do |dir_to_make|
|
||||||
|
@ -71,7 +76,7 @@ module Rails
|
||||||
begin
|
begin
|
||||||
logger = ActiveSupport::BufferedLogger.new(config.log_path)
|
logger = ActiveSupport::BufferedLogger.new(config.log_path)
|
||||||
logger.level = ActiveSupport::BufferedLogger.const_get(config.log_level.to_s.upcase)
|
logger.level = ActiveSupport::BufferedLogger.const_get(config.log_level.to_s.upcase)
|
||||||
if RAILS_ENV == "production"
|
if Rails.env.production?
|
||||||
logger.auto_flushing = false
|
logger.auto_flushing = false
|
||||||
end
|
end
|
||||||
rescue StandardError => e
|
rescue StandardError => e
|
||||||
|
|
|
@ -4,8 +4,6 @@ require "irb/completion"
|
||||||
|
|
||||||
module Rails
|
module Rails
|
||||||
class Console
|
class Console
|
||||||
ENVIRONMENTS = %w(production development test)
|
|
||||||
|
|
||||||
def self.start(app)
|
def self.start(app)
|
||||||
new(app).start
|
new(app).start
|
||||||
end
|
end
|
||||||
|
@ -25,10 +23,6 @@ module Rails
|
||||||
opt.parse!(ARGV)
|
opt.parse!(ARGV)
|
||||||
end
|
end
|
||||||
|
|
||||||
if env = ARGV.pop
|
|
||||||
ENV['RAILS_ENV'] = ENVIRONMENTS.find { |e| e.index(env) } || env
|
|
||||||
end
|
|
||||||
|
|
||||||
@app.initialize!
|
@app.initialize!
|
||||||
require "rails/console_app"
|
require "rails/console_app"
|
||||||
require "rails/console_sandbox" if options[:sandbox]
|
require "rails/console_sandbox" if options[:sandbox]
|
||||||
|
@ -54,3 +48,8 @@ module Rails
|
||||||
end
|
end
|
||||||
end
|
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
|
||||||
|
|
|
@ -34,7 +34,6 @@ module Rails
|
||||||
abort opt.to_s unless (0..1).include?(ARGV.size)
|
abort opt.to_s unless (0..1).include?(ARGV.size)
|
||||||
end
|
end
|
||||||
|
|
||||||
env = ARGV.first || ENV['RAILS_ENV'] || 'development'
|
|
||||||
unless config = YAML::load(ERB.new(IO.read("#{@app.root}/config/database.yml")).result)[env]
|
unless config = YAML::load(ERB.new(IO.read("#{@app.root}/config/database.yml")).result)[env]
|
||||||
abort "No database is configured for the environment '#{env}'"
|
abort "No database is configured for the environment '#{env}'"
|
||||||
end
|
end
|
||||||
|
@ -98,3 +97,8 @@ module Rails
|
||||||
end
|
end
|
||||||
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
|
|
@ -34,7 +34,6 @@ end
|
||||||
ARGV.delete(code_or_file)
|
ARGV.delete(code_or_file)
|
||||||
|
|
||||||
ENV["RAILS_ENV"] = options[:environment]
|
ENV["RAILS_ENV"] = options[:environment]
|
||||||
RAILS_ENV.replace(options[:environment]) if defined?(RAILS_ENV)
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
if code_or_file.nil?
|
if code_or_file.nil?
|
||||||
|
|
|
@ -38,15 +38,14 @@ module Rails
|
||||||
end
|
end
|
||||||
|
|
||||||
def start
|
def start
|
||||||
|
ENV["RAILS_ENV"] = options[:environment]
|
||||||
|
|
||||||
puts "=> Booting #{ActiveSupport::Inflector.demodulize(server)}"
|
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]
|
puts "=> Call with -d to detach" unless options[:daemonize]
|
||||||
trap(:INT) { exit }
|
trap(:INT) { exit }
|
||||||
puts "=> Ctrl-C to shutdown server" unless options[:daemonize]
|
puts "=> Ctrl-C to shutdown server" unless options[:daemonize]
|
||||||
|
|
||||||
ENV["RAILS_ENV"] = options[:environment]
|
|
||||||
RAILS_ENV.replace(options[:environment]) if defined?(RAILS_ENV)
|
|
||||||
|
|
||||||
super
|
super
|
||||||
ensure
|
ensure
|
||||||
puts 'Exiting' unless options[:daemonize]
|
puts 'Exiting' unless options[:daemonize]
|
||||||
|
|
|
@ -129,7 +129,7 @@ module Rails
|
||||||
paths.tmp.cache "tmp/cache"
|
paths.tmp.cache "tmp/cache"
|
||||||
paths.config "config"
|
paths.config "config"
|
||||||
paths.config.locales "config/locales"
|
paths.config.locales "config/locales"
|
||||||
paths.config.environments "config/environments", :glob => "#{RAILS_ENV}.rb"
|
paths.config.environments "config/environments", :glob => "#{Rails.env}.rb"
|
||||||
paths
|
paths
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -212,7 +212,7 @@ module Rails
|
||||||
paths = []
|
paths = []
|
||||||
|
|
||||||
# Add the old mock paths only if the directories exists
|
# 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
|
# Add the app's controller directory
|
||||||
paths.concat(Dir["#{root}/app/controllers/"])
|
paths.concat(Dir["#{root}/app/controllers/"])
|
||||||
|
@ -235,15 +235,15 @@ module Rails
|
||||||
|
|
||||||
def builtin_directories
|
def builtin_directories
|
||||||
# Include builtins only in the development environment.
|
# Include builtins only in the development environment.
|
||||||
(RAILS_ENV == 'development') ? Dir["#{RAILTIES_PATH}/builtin/*/"] : []
|
Rails.env.development? ? Dir["#{RAILTIES_PATH}/builtin/*/"] : []
|
||||||
end
|
end
|
||||||
|
|
||||||
def log_path
|
def log_path
|
||||||
@log_path ||= File.join(root, 'log', "#{RAILS_ENV}.log")
|
@log_path ||= File.join(root, 'log', "#{Rails.env}.log")
|
||||||
end
|
end
|
||||||
|
|
||||||
def log_level
|
def log_level
|
||||||
@log_level ||= RAILS_ENV == 'production' ? :info : :debug
|
@log_level ||= Rails.env.production? ? :info : :debug
|
||||||
end
|
end
|
||||||
|
|
||||||
def time_zone
|
def time_zone
|
||||||
|
@ -265,7 +265,7 @@ module Rails
|
||||||
end
|
end
|
||||||
|
|
||||||
def environment_path
|
def environment_path
|
||||||
"#{root}/config/environments/#{RAILS_ENV}.rb"
|
"#{root}/config/environments/#{Rails.env}.rb"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Holds generators configuration:
|
# Holds generators configuration:
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
require File.expand_path('../../config/application', __FILE__)
|
require File.expand_path('../../config/boot', __FILE__)
|
||||||
require 'rails/commands/console'
|
require 'rails/commands/console'
|
||||||
|
require File.expand_path('../../config/application', __FILE__)
|
||||||
|
|
||||||
Rails::Console.start(<%= app_const %>.instance)
|
Rails::Console.start(<%= app_const %>.instance)
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
require File.expand_path('../../config/application', __FILE__)
|
require File.expand_path('../../config/boot', __FILE__)
|
||||||
require 'rails/commands/dbconsole'
|
require 'rails/commands/dbconsole'
|
||||||
|
require File.expand_path('../../config/application', __FILE__)
|
||||||
|
|
||||||
Rails::DBConsole.start(<%= app_const %>.instance)
|
Rails::DBConsole.start(<%= app_const %>.instance)
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
require File.expand_path('../../config/environment', __FILE__)
|
require File.expand_path('../../config/boot', __FILE__)
|
||||||
require 'rails/commands/runner'
|
require 'rails/commands/runner'
|
||||||
|
require File.expand_path('../../config/environment', __FILE__)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Make double-sure the RAILS_ENV is set to test,
|
# Make double-sure the RAILS_ENV is set to test,
|
||||||
# so fixtures are loaded to the right database
|
# 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 'test/unit'
|
||||||
require 'active_support/core_ext/kernel/requires'
|
require 'active_support/core_ext/kernel/requires'
|
||||||
|
|
Loading…
Reference in a new issue