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.rb83
1 files changed, 50 insertions, 33 deletions
diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb
index 3d94cedb47..b8b071d4c9 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
@@ -90,7 +98,7 @@ module Rails
# Rails::Initializer.run(:set_load_path)
#
# This is useful if you only want the load path initialized, without
- # incuring the overhead of completely loading the entire environment.
+ # incurring the overhead of completely loading the entire environment.
def self.run(command = :process, configuration = Configuration.new)
yield configuration if block_given?
initializer = new configuration
@@ -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
@@ -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
@@ -399,8 +414,11 @@ module Rails
# paths have already been set, it is not changed, otherwise it is
# set to use Configuration#view_path.
def initialize_framework_views
- ActionMailer::Base.template_root ||= configuration.view_path if configuration.frameworks.include?(:action_mailer)
- ActionController::Base.view_paths = [configuration.view_path] if configuration.frameworks.include?(:action_controller) && ActionController::Base.view_paths.empty?
+ ActionView::PathSet::Path.eager_load_templates! if configuration.cache_classes
+ view_path = ActionView::PathSet::Path.new(configuration.view_path)
+
+ ActionMailer::Base.template_root ||= view_path if configuration.frameworks.include?(:action_mailer)
+ ActionController::Base.view_paths = view_path if configuration.frameworks.include?(:action_controller) && ActionController::Base.view_paths.empty?
end
# If Action Controller is not one of the loaded frameworks (Configuration#frameworks)
@@ -486,7 +504,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
@@ -514,7 +531,7 @@ module Rails
# A stub for setting options on ActiveRecord::Base.
attr_accessor :active_record
- # A stub for setting options on ActiveRecord::Base.
+ # A stub for setting options on ActiveResource::Base.
attr_accessor :active_resource
# A stub for setting options on ActiveSupport.
@@ -531,7 +548,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 +614,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 +651,7 @@ module Rails
def gem(name, options = {})
@gems << Rails::GemDependency.new(name, options)
end
-
+
# Deprecated options:
def breakpoint_server(_ = nil)
$stderr.puts %(
@@ -693,7 +710,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 +751,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 +765,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 +784,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 +870,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 +878,7 @@ module Rails
:memory_store
end
end
-
+
def default_gems
[]
end