From 1edb5c85b58653a6fdc73ae1c6c63e317b466b27 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 15 Jul 2008 15:50:37 -0700 Subject: Give more info on missing gems and abort instead of printing a warning. App can begin in incomplete state otherwise. --- railties/lib/initializer.rb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'railties/lib/initializer.rb') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 18bcf69d69..7808d88d92 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -266,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 -- cgit v1.2.3 From 83e29b9773ac113ceacb1e36c2f333d692de2573 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 15 Jul 2008 22:51:16 -0500 Subject: Removed config.action_view.cache_template_loading, use config.cache_classes instead --- railties/lib/initializer.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/lib/initializer.rb') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 7808d88d92..0b052e1fda 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -414,6 +414,7 @@ Run `rake gems:install` to install the missing gems. # paths have already been set, it is not changed, otherwise it is # set to use Configuration#view_path. def initialize_framework_views + ActionView::PathSet::Path.eager_load_templates! if configuration.cache_classes 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? end -- cgit v1.2.3 From fea5b6fd41f7d667fe637c9e9e31b51489ee5a50 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 15 Jul 2008 22:57:20 -0500 Subject: ActionMailer and ActionView can share the same view path cache --- railties/lib/initializer.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'railties/lib/initializer.rb') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 0b052e1fda..b9e890a3e4 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -415,8 +415,10 @@ Run `rake gems:install` to install the missing gems. # set to use Configuration#view_path. def initialize_framework_views ActionView::PathSet::Path.eager_load_templates! if configuration.cache_classes - 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) + + 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) -- cgit v1.2.3 From 0432d151647f2178ddee79979827d552447c251f Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Wed, 16 Jul 2008 13:00:36 +0100 Subject: Merge with docrails. --- railties/lib/initializer.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/lib/initializer.rb') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index b9e890a3e4..b8b071d4c9 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -98,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 @@ -531,7 +531,7 @@ Run `rake gems:install` to install the missing gems. # 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. -- cgit v1.2.3 From 3bd34b6ffe017dd81fd26743aab052fc4324eb0f Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 14 Jun 2008 16:24:23 -0500 Subject: Preload application classes. Uses same strategy as phusion passenger. --- railties/lib/initializer.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'railties/lib/initializer.rb') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index b8b071d4c9..3be95de8d3 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -168,6 +168,9 @@ module Rails # Observers are loaded after plugins in case Observers or observed models are modified by plugins. load_observers + # load application classes + load_application_classes + # Flag initialized Rails.initialized = true end @@ -330,6 +333,14 @@ Run `rake gems:install` to install the missing gems. end end + def load_application_classes + require_dependency 'application' + + Dir.glob('app/{models,controllers,helpers}/*.rb').each do |file| + require_dependency file + 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+ -- cgit v1.2.3 From 89ec72c2818a592323fe4ec3277638d379f1ac2a Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 21 Jul 2008 13:42:34 -0500 Subject: Added configurable eager load paths. Defaults to app/models, app/controllers, and app/helpers --- railties/lib/initializer.rb | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'railties/lib/initializer.rb') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 3be95de8d3..828d688475 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -333,11 +333,14 @@ Run `rake gems:install` to install the missing gems. end end + # Eager load application classes def load_application_classes - require_dependency 'application' - - Dir.glob('app/{models,controllers,helpers}/*.rb').each do |file| - require_dependency file + 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 @@ -578,6 +581,11 @@ Run `rake gems:install` to install the missing gems. # 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 :info. In development mode, it defaults to # :debug. @@ -686,6 +694,7 @@ Run `rake gems:install` to install the missing gems. 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 @@ -826,6 +835,14 @@ Run `rake gems:install` to install the missing gems. [] 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 -- cgit v1.2.3 From 97a954bf1dd05e79a873bffc94fcf5420b807371 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 23 Jul 2008 10:41:28 -0500 Subject: Load view path cache after plugins and gems. --- railties/lib/initializer.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'railties/lib/initializer.rb') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 828d688475..97bb81a3c8 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -168,6 +168,9 @@ 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 @@ -333,6 +336,12 @@ Run `rake gems:install` to install the missing gems. end end + def load_view_paths + ActionView::PathSet::Path.eager_load_templates! if configuration.cache_classes + ActionMailer::Base.template_root.load + ActionController::Base.view_paths.load + end + # Eager load application classes def load_application_classes if configuration.cache_classes @@ -428,9 +437,7 @@ Run `rake gems:install` to install the missing gems. # paths have already been set, it is not changed, otherwise it is # set to use Configuration#view_path. def initialize_framework_views - ActionView::PathSet::Path.eager_load_templates! if configuration.cache_classes - view_path = ActionView::PathSet::Path.new(configuration.view_path) - + 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 -- cgit v1.2.3 From 3fd9036fc554979e951422a79f0f77f061112bdc Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Thu, 24 Jul 2008 11:58:26 -0500 Subject: Added config.dependency_loading to enable or disable the dependency loader after initialization --- railties/lib/initializer.rb | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'railties/lib/initializer.rb') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 97bb81a3c8..44863ab026 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -171,9 +171,12 @@ module Rails # Load view path cache load_view_paths - # load application classes + # Load application classes load_application_classes + # Disable dependency loading during request cycle + disable_dependency_loading + # Flag initialized Rails.initialized = true end @@ -525,6 +528,12 @@ Run `rake gems:install` to install the missing gems. 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 @@ -659,6 +668,17 @@ Run `rake gems:install` to install the missing gems. !!@reload_plugins end + # Enables or disables dependency loading during the request cycle. Setting + # dependency_loading 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 cache_classes 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: # @@ -707,6 +727,7 @@ Run `rake gems:install` to install the missing gems. 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 @@ -876,8 +897,8 @@ Run `rake gems:install` to install the missing gems. paths end - def default_dependency_mechanism - :load + def default_dependency_loading + true end def default_cache_classes -- cgit v1.2.3 From 11fdcf88c2aea72ec84c5d4ab05986f5d35a9a81 Mon Sep 17 00:00:00 2001 From: Sam Granieri Date: Thu, 24 Jul 2008 13:51:54 -0500 Subject: Check for ActionMailer and ActionController before attempting to eager load their view paths Signed-off-by: Joshua Peek --- railties/lib/initializer.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/lib/initializer.rb') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 44863ab026..32411e8928 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -341,8 +341,8 @@ Run `rake gems:install` to install the missing gems. def load_view_paths ActionView::PathSet::Path.eager_load_templates! if configuration.cache_classes - ActionMailer::Base.template_root.load - ActionController::Base.view_paths.load + 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 -- cgit v1.2.3