aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/initializer.rb
diff options
context:
space:
mode:
Diffstat (limited to 'railties/lib/initializer.rb')
-rw-r--r--railties/lib/initializer.rb80
1 files changed, 47 insertions, 33 deletions
diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb
index f0b5e3f257..7808d88d92 100644
--- a/railties/lib/initializer.rb
+++ b/railties/lib/initializer.rb
@@ -19,15 +19,23 @@ module Rails
def configuration
@@configuration
end
-
+
def configuration=(configuration)
@@configuration = configuration
end
-
+
+ def initialized?
+ @initialized || false
+ end
+
+ def initialized=(initialized)
+ @initialized ||= initialized
+ end
+
def logger
RAILS_DEFAULT_LOGGER
end
-
+
def root
if defined?(RAILS_ROOT)
RAILS_ROOT
@@ -35,11 +43,11 @@ module Rails
nil
end
end
-
+
def env
ActiveSupport::StringInquirer.new(RAILS_ENV)
end
-
+
def cache
RAILS_CACHE
end
@@ -56,7 +64,7 @@ module Rails
@@public_path = path
end
end
-
+
# The Initializer is responsible for processing the Rails configuration, such
# as setting the $LOAD_PATH, requiring the right frameworks, initializing
# logging, and more. It can be run either as a single command that'll just
@@ -113,10 +121,10 @@ module Rails
check_ruby_version
install_gem_spec_stubs
set_load_path
-
+ add_gem_load_paths
+
require_frameworks
set_autoload_paths
- add_gem_load_paths
add_plugin_load_paths
load_environment
@@ -129,12 +137,12 @@ module Rails
initialize_logger
initialize_framework_logging
- initialize_framework_views
initialize_dependency_mechanism
initialize_whiny_nils
initialize_temporary_session_directory
initialize_time_zone
initialize_framework_settings
+ initialize_framework_views
add_support_load_paths
@@ -145,7 +153,7 @@ module Rails
add_gem_load_paths
load_gems
check_gem_dependencies
-
+
load_application_initializers
# the framework is now fully initialized
@@ -158,8 +166,10 @@ module Rails
initialize_routing
# Observers are loaded after plugins in case Observers or observed models are modified by plugins.
-
load_observers
+
+ # Flag initialized
+ Rails.initialized = true
end
# Check for valid Ruby version
@@ -242,12 +252,12 @@ module Rails
def add_gem_load_paths
unless @configuration.gems.empty?
require "rubygems"
- @configuration.gems.each &:add_load_paths
+ @configuration.gems.each { |gem| gem.add_load_paths }
end
end
def load_gems
- @configuration.gems.each(&:load)
+ @configuration.gems.each { |gem| gem.load }
end
def check_gem_dependencies
@@ -256,11 +266,16 @@ module Rails
@gems_dependencies_loaded = false
# don't print if the gems rake tasks are being run
unless $rails_gem_installer
- puts %{These gems that this application depends on are missing:}
- unloaded_gems.each do |gem|
- puts " - #{gem.name}"
- end
- puts %{Run "rake gems:install" to install them.}
+ abort <<-end_error
+Missing these required gems:
+ #{unloaded_gems.map { |gem| "#{gem.name} #{gem.requirement}" } * "\n "}
+
+You're running:
+ ruby #{Gem.ruby_version} at #{Gem.ruby}
+ rubygems #{Gem::RubyGemsVersion} at #{Gem.path * ', '}
+
+Run `rake gems:install` to install the missing gems.
+ end_error
end
else
@gems_dependencies_loaded = true
@@ -297,12 +312,12 @@ module Rails
silence_warnings do
return if @environment_loaded
@environment_loaded = true
-
+
config = configuration
constants = self.class.constants
-
+
eval(IO.read(configuration.environment_path), binding, configuration.environment_path)
-
+
(self.class.constants - constants).each do |const|
Object.const_set(const, self.class.const_get(const))
end
@@ -390,7 +405,7 @@ module Rails
for framework in ([ :active_record, :action_controller, :action_mailer ] & configuration.frameworks)
framework.to_s.camelize.constantize.const_get("Base").logger ||= RAILS_DEFAULT_LOGGER
end
-
+
RAILS_CACHE.logger ||= RAILS_DEFAULT_LOGGER
end
@@ -486,7 +501,6 @@ module Rails
Dispatcher.define_dispatcher_callbacks(configuration.cache_classes)
Dispatcher.new(RAILS_DEFAULT_LOGGER).send :run_callbacks, :prepare_dispatch
end
-
end
# The Configuration class holds all the parameters for the Initializer and
@@ -531,7 +545,7 @@ module Rails
# The path to the database configuration file to use. (Defaults to
# <tt>config/database.yml</tt>.)
attr_accessor :database_configuration_file
-
+
# The path to the routes configuration file to use. (Defaults to
# <tt>config/routes.rb</tt>.)
attr_accessor :routes_configuration_file
@@ -597,7 +611,7 @@ module Rails
# a sub class would have access to fine grained modification of the loading behavior. See
# the implementation of Rails::Plugin::Loader for more details.
attr_accessor :plugin_loader
-
+
# Enables or disables plugin reloading. You can get around this setting per plugin.
# If <tt>reload_plugins?</tt> is false, add this to your plugin's <tt>init.rb</tt>
# to make it reloadable:
@@ -634,7 +648,7 @@ module Rails
def gem(name, options = {})
@gems << Rails::GemDependency.new(name, options)
end
-
+
# Deprecated options:
def breakpoint_server(_ = nil)
$stderr.puts %(
@@ -693,7 +707,7 @@ module Rails
else
Pathname.new(::RAILS_ROOT).realpath.to_s
end
-
+
Object.const_set(:RELATIVE_RAILS_ROOT, ::RAILS_ROOT.dup) unless defined?(::RELATIVE_RAILS_ROOT)
::RAILS_ROOT.replace @root_path
end
@@ -734,7 +748,7 @@ module Rails
#
# See Dispatcher#to_prepare.
def to_prepare(&callback)
- after_initialize do
+ after_initialize do
require 'dispatcher' unless defined?(::Dispatcher)
Dispatcher.to_prepare(&callback)
end
@@ -748,11 +762,11 @@ module Rails
def framework_paths
paths = %w(railties railties/lib activesupport/lib)
paths << 'actionpack/lib' if frameworks.include? :action_controller or frameworks.include? :action_view
-
+
[:active_record, :action_mailer, :active_resource, :action_web_service].each do |framework|
paths << "#{framework.to_s.gsub('_', '')}/lib" if frameworks.include? framework
end
-
+
paths.map { |dir| "#{framework_root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
end
@@ -767,7 +781,7 @@ module Rails
def default_load_paths
paths = []
-
+
# Add the old mock paths only if the directories exists
paths.concat(Dir["#{root_path}/test/mocks/#{environment}"]) if File.exists?("#{root_path}/test/mocks/#{environment}")
@@ -853,7 +867,7 @@ module Rails
def default_plugin_loader
Plugin::Loader
end
-
+
def default_cache_store
if File.exist?("#{root_path}/tmp/cache/")
[ :file_store, "#{root_path}/tmp/cache/" ]
@@ -861,7 +875,7 @@ module Rails
:memory_store
end
end
-
+
def default_gems
[]
end