aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/initializer.rb
diff options
context:
space:
mode:
authorTomK32 <tomk32@tomk32.de>2008-06-11 19:22:51 +0200
committerTomK32 <tomk32@tomk32.de>2008-06-11 19:22:51 +0200
commit6a5ac86207765e2c041378b35c05812f9bfe68b9 (patch)
tree4b341329991f2bd08c01d2f139c4c3721a8fbe25 /railties/lib/initializer.rb
parentfa0cca368f74119b561595cc6ca7454f7debdf6b (diff)
parentd4b7cd99e8e7051c9d3ed6722f9627d5d4dea4e9 (diff)
downloadrails-6a5ac86207765e2c041378b35c05812f9bfe68b9.tar.gz
rails-6a5ac86207765e2c041378b35c05812f9bfe68b9.tar.bz2
rails-6a5ac86207765e2c041378b35c05812f9bfe68b9.zip
Merge branch 'master' of git@github.com:lifo/docrails
Diffstat (limited to 'railties/lib/initializer.rb')
-rw-r--r--railties/lib/initializer.rb94
1 files changed, 59 insertions, 35 deletions
diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb
index dfd43042be..ec065e6f3c 100644
--- a/railties/lib/initializer.rb
+++ b/railties/lib/initializer.rb
@@ -8,6 +8,7 @@ require 'rails/version'
require 'rails/plugin/locator'
require 'rails/plugin/loader'
require 'rails/gem_dependency'
+require 'rails/rack'
RAILS_ENV = (ENV['RAILS_ENV'] || 'development').dup unless defined?(RAILS_ENV)
@@ -43,6 +44,10 @@ module Rails
RAILS_CACHE
end
+ def version
+ VERSION::STRING
+ end
+
def public_path
@@public_path ||= self.root ? File.join(self.root, "public") : "public"
end
@@ -82,7 +87,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
@@ -136,7 +141,8 @@ module Rails
# pick up any gems that plugins depend on
add_gem_load_paths
load_gems
-
+ check_gem_dependencies
+
load_application_initializers
# the framework is now fully initialized
@@ -149,6 +155,7 @@ module Rails
initialize_routing
# Observers are loaded after plugins in case Observers or observed models are modified by plugins.
+
load_observers
end
@@ -160,12 +167,12 @@ module Rails
end
# If Rails is vendored and RubyGems is available, install stub GemSpecs
- # for Rails, ActiveSupport, ActiveRecord, ActionPack, ActionMailer, and
- # ActiveResource. This allows Gem plugins to depend on Rails even when
+ # for Rails, Active Support, Active Record, Action Pack, Action Mailer, and
+ # Active Resource. This allows Gem plugins to depend on Rails even when
# the Gem version of Rails shouldn't be loaded.
def install_gem_spec_stubs
unless Rails.respond_to?(:vendor_rails?)
- abort "Your config/boot.rb is outdated: Run 'rake rails:update'."
+ abort %{Your config/boot.rb is outdated: Run "rake rails:update".}
end
if Rails.vendor_rails?
@@ -210,8 +217,8 @@ module Rails
end
# Requires all frameworks specified by the Configuration#frameworks
- # list. By default, all frameworks (ActiveRecord, ActiveSupport,
- # ActionPack, ActionMailer, and ActiveResource) are loaded.
+ # list. By default, all frameworks (Active Record, Active Support,
+ # Action Pack, Action Mailer, and Active Resource) are loaded.
def require_frameworks
configuration.frameworks.each { |framework| require(framework.to_s) }
rescue LoadError => e
@@ -237,7 +244,24 @@ module Rails
end
def load_gems
- @configuration.gems.each &:load
+ @configuration.gems.each(&:load)
+ end
+
+ def check_gem_dependencies
+ unloaded_gems = @configuration.gems.reject { |g| g.loaded? }
+ if unloaded_gems.size > 0
+ @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.}
+ end
+ else
+ @gems_dependencies_loaded = true
+ end
end
# Loads all plugins in <tt>config.plugin_paths</tt>. <tt>plugin_paths</tt>
@@ -283,12 +307,8 @@ module Rails
end
def load_observers
- if configuration.frameworks.include?(:active_record)
- if @configuration.gems.any? { |g| !g.loaded? }
- puts "Unable to instantiate observers, some gems that this application depends on are missing. Run 'rake gems:install'"
- else
- ActiveRecord::Base.instantiate_observers
- end
+ if @gems_dependencies_loaded && configuration.frameworks.include?(:active_record)
+ ActiveRecord::Base.instantiate_observers
end
end
@@ -326,7 +346,7 @@ module Rails
end
end
- # If the +RAILS_DEFAULT_LOGGER+ constant is already set, this initialization
+ # If the RAILS_DEFAULT_LOGGER constant is already set, this initialization
# routine does nothing. If the constant is not set, and Configuration#logger
# is not +nil+, this also does nothing. Otherwise, a new logger instance
# is created at Configuration#log_path, with a default log level of
@@ -359,10 +379,10 @@ module Rails
silence_warnings { Object.const_set "RAILS_DEFAULT_LOGGER", logger }
end
- # Sets the logger for ActiveRecord, ActionController, and ActionMailer
+ # Sets the logger for Active Record, Action Controller, and Action Mailer
# (but only for those frameworks that are to be loaded). If the framework's
# logger is already set, it is not changed, otherwise it is set to use
- # +RAILS_DEFAULT_LOGGER+.
+ # RAILS_DEFAULT_LOGGER.
def initialize_framework_logging
for framework in ([ :active_record, :action_controller, :action_mailer ] & configuration.frameworks)
framework.to_s.camelize.constantize.const_get("Base").logger ||= RAILS_DEFAULT_LOGGER
@@ -380,7 +400,7 @@ module Rails
ActionController::Base.view_paths = [configuration.view_path] if configuration.frameworks.include?(:action_controller) && ActionController::Base.view_paths.empty?
end
- # If ActionController is not one of the loaded frameworks (Configuration#frameworks)
+ # If Action Controller is not one of the loaded frameworks (Configuration#frameworks)
# this does nothing. Otherwise, it loads the routing definitions and sets up
# loading module used to lazily load controllers (Configuration#controller_paths).
def initialize_routing
@@ -409,13 +429,13 @@ module Rails
end
end
- # Sets the default value for Time.zone, and turns on ActiveRecord time_zone_aware_attributes.
+ # Sets the default value for Time.zone, and turns on ActiveRecord::Base#time_zone_aware_attributes.
# If assigned value cannot be matched to a TimeZone, an exception will be raised.
def initialize_time_zone
if configuration.time_zone
zone_default = Time.send!(:get_zone, configuration.time_zone)
unless zone_default
- raise "Value assigned to config.time_zone not recognized. Run `rake -D time` for a list of tasks for finding appropriate time zone names."
+ raise %{Value assigned to config.time_zone not recognized. Run "rake -D time" for a list of tasks for finding appropriate time zone names.}
end
Time.zone_default = zone_default
if configuration.frameworks.include?(:active_record)
@@ -443,14 +463,18 @@ module Rails
# Fires the user-supplied after_initialize block (Configuration#after_initialize)
def after_initialize
- configuration.after_initialize_blocks.each do |block|
- block.call
+ if @gems_dependencies_loaded
+ configuration.after_initialize_blocks.each do |block|
+ block.call
+ end
end
end
def load_application_initializers
- Dir["#{configuration.root_path}/config/initializers/**/*.rb"].sort.each do |initializer|
- load(initializer)
+ if @gems_dependencies_loaded
+ Dir["#{configuration.root_path}/config/initializers/**/*.rb"].sort.each do |initializer|
+ load(initializer)
+ end
end
end
@@ -475,22 +499,22 @@ module Rails
# The application's base directory.
attr_reader :root_path
- # A stub for setting options on ActionController::Base
+ # A stub for setting options on ActionController::Base.
attr_accessor :action_controller
- # A stub for setting options on ActionMailer::Base
+ # A stub for setting options on ActionMailer::Base.
attr_accessor :action_mailer
- # A stub for setting options on ActionView::Base
+ # A stub for setting options on ActionView::Base.
attr_accessor :action_view
- # A stub for setting options on ActiveRecord::Base
+ # 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 ActiveRecord::Base.
attr_accessor :active_resource
- # A stub for setting options on ActiveSupport
+ # A stub for setting options on ActiveSupport.
attr_accessor :active_support
# Whether or not classes should be cached (set to false if you want
@@ -618,9 +642,9 @@ module Rails
end
alias_method :breakpoint_server=, :breakpoint_server
- # Sets the default time_zone. Setting this will enable time_zone
- # awareness for ActiveRecord models and set the ActiveRecord default
- # timezone to :utc.
+ # Sets the default +time_zone+. Setting this will enable +time_zone+
+ # awareness for Active Record models and set the Active Record default
+ # timezone to <tt>:utc</tt>.
attr_accessor :time_zone
# Create a new Configuration instance, initialized with the default
@@ -685,7 +709,7 @@ module Rails
end
# Return the currently selected environment. By default, it returns the
- # value of the +RAILS_ENV+ constant.
+ # value of the RAILS_ENV constant.
def environment
::RAILS_ENV
end
@@ -843,7 +867,7 @@ end
# Needs to be duplicated from Active Support since its needed before Active
# Support is available. Here both Options and Hash are namespaced to prevent
-# conflicts with other implementations AND with the classes residing in ActiveSupport.
+# conflicts with other implementations AND with the classes residing in Active Support.
class Rails::OrderedOptions < Array #:nodoc:
def []=(key, value)
key = key.to_sym