aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/initializer.rb
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2008-07-28 12:03:16 +0100
committerPratik Naik <pratiknaik@gmail.com>2008-07-28 12:03:16 +0100
commitde211914d84737c4314e862b459b9a23a0baa28f (patch)
tree3f04c940a4c821014332ddc4f119a81a37db3a33 /railties/lib/initializer.rb
parent6246a8e06035973c88a38826ce1ee6b07b03b8dc (diff)
parent10d9fe4bf3110c1d5de0c6b509fe0cbb9d5eda1d (diff)
downloadrails-de211914d84737c4314e862b459b9a23a0baa28f.tar.gz
rails-de211914d84737c4314e862b459b9a23a0baa28f.tar.bz2
rails-de211914d84737c4314e862b459b9a23a0baa28f.zip
Merge commit 'mainstream/master'
Conflicts: actionpack/lib/action_controller/cookies.rb actionpack/lib/action_controller/streaming.rb actionpack/lib/action_controller/test_case.rb actionpack/lib/action_view/base.rb actionpack/lib/action_view/helpers/date_helper.rb actionpack/lib/action_view/helpers/debug_helper.rb actionpack/lib/action_view/helpers/form_options_helper.rb actionpack/lib/action_view/helpers/javascript_helper.rb activerecord/lib/active_record/associations.rb activerecord/lib/active_record/validations.rb activeresource/README activesupport/lib/active_support/core_ext/hash/reverse_merge.rb activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/data_timezone_info.rb activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/timezone.rb railties/doc/guides/actionview/helpers.markdown railties/doc/guides/actionview/partials.markdown railties/doc/guides/activerecord/basics.markdown
Diffstat (limited to 'railties/lib/initializer.rb')
-rw-r--r--railties/lib/initializer.rb82
1 files changed, 73 insertions, 9 deletions
diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb
index dbd24df9b0..32411e8928 100644
--- a/railties/lib/initializer.rb
+++ b/railties/lib/initializer.rb
@@ -168,6 +168,15 @@ module Rails
# Observers are loaded after plugins in case Observers or observed models are modified by plugins.
load_observers
+ # Load view path cache
+ load_view_paths
+
+ # Load application classes
+ load_application_classes
+
+ # Disable dependency loading during request cycle
+ disable_dependency_loading
+
# Flag initialized
Rails.initialized = true
end
@@ -266,11 +275,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
@@ -325,6 +339,23 @@ module Rails
end
end
+ def load_view_paths
+ ActionView::PathSet::Path.eager_load_templates! if configuration.cache_classes
+ ActionMailer::Base.template_root.load if configuration.frameworks.include?(:action_mailer)
+ ActionController::Base.view_paths.load if configuration.frameworks.include?(:action_controller)
+ end
+
+ # Eager load application classes
+ def load_application_classes
+ if configuration.cache_classes
+ configuration.eager_load_paths.each do |load_path|
+ Dir.glob("#{load_path}/*.rb").each do |file|
+ require_dependency file
+ end
+ end
+ end
+ end
+
# For Ruby 1.8, this initialization sets $KCODE to 'u' to enable the
# multibyte safe operations. Plugin authors supporting other encodings
# should override this behaviour and set the relevant +default_charset+
@@ -409,8 +440,9 @@ 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?
+ view_path = ActionView::PathSet::Path.new(configuration.view_path, false)
+ 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)
@@ -496,6 +528,12 @@ module Rails
Dispatcher.define_dispatcher_callbacks(configuration.cache_classes)
Dispatcher.new(RAILS_DEFAULT_LOGGER).send :run_callbacks, :prepare_dispatch
end
+
+ def disable_dependency_loading
+ if configuration.cache_classes && !configuration.dependency_loading
+ ActiveSupport::Dependencies.unhook!
+ end
+ end
end
# The Configuration class holds all the parameters for the Initializer and
@@ -559,6 +597,11 @@ module Rails
# All elements of this array must also be in +load_paths+.
attr_accessor :load_once_paths
+ # An array of paths from which Rails will eager load on boot if cache
+ # classes is enabled. All elements of this array must also be in
+ # +load_paths+.
+ attr_accessor :eager_load_paths
+
# The log level to use for the default Rails logger. In production mode,
# this defaults to <tt>:info</tt>. In development mode, it defaults to
# <tt>:debug</tt>.
@@ -625,6 +668,17 @@ module Rails
!!@reload_plugins
end
+ # Enables or disables dependency loading during the request cycle. Setting
+ # <tt>dependency_loading</tt> to true will allow new classes to be loaded
+ # during a request. Setting it to false will disable this behavior.
+ #
+ # Those who want to run in a threaded environment should disable this
+ # option and eager load or require all there classes on initialization.
+ #
+ # If <tt>cache_classes</tt> is disabled, dependency loaded will always be
+ # on.
+ attr_accessor :dependency_loading
+
# An array of gems that this rails application depends on. Rails will automatically load
# these gems during installation, and allow you to install any missing gems with:
#
@@ -667,11 +721,13 @@ module Rails
self.frameworks = default_frameworks
self.load_paths = default_load_paths
self.load_once_paths = default_load_once_paths
+ self.eager_load_paths = default_eager_load_paths
self.log_path = default_log_path
self.log_level = default_log_level
self.view_path = default_view_path
self.controller_paths = default_controller_paths
self.cache_classes = default_cache_classes
+ self.dependency_loading = default_dependency_loading
self.whiny_nils = default_whiny_nils
self.plugins = default_plugins
self.plugin_paths = default_plugin_paths
@@ -807,6 +863,14 @@ module Rails
[]
end
+ def default_eager_load_paths
+ %w(
+ app/models
+ app/controllers
+ app/helpers
+ ).map { |dir| "#{root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
+ end
+
def default_log_path
File.join(root_path, 'log', "#{environment}.log")
end
@@ -833,8 +897,8 @@ module Rails
paths
end
- def default_dependency_mechanism
- :load
+ def default_dependency_loading
+ true
end
def default_cache_classes