5
$LOAD_PATH.unshift File.dirname(__FILE__)
6
require 'railties_path'
7
require 'rails/version'
8
require 'rails/plugin/locator'
9
require 'rails/plugin/loader'
10
require 'rails/gem_dependency'
14
RAILS_ENV = (ENV['RAILS_ENV'] || 'development').dup unless defined?(RAILS_ENV)
18
# The Configuration instance used to configure the Rails environment
23
def configuration=(configuration)
24
@@configuration = configuration
31
def initialized=(initialized)
32
@initialized ||= initialized
36
if defined?(RAILS_DEFAULT_LOGGER)
44
@@backtrace_cleaner ||= begin
45
# Relies on ActiveSupport, so we have to lazy load to postpone definition until AS has been loaded
46
require 'rails/backtrace_cleaner'
47
Rails::BacktraceCleaner.new
52
Pathname.new(RAILS_ROOT) if defined?(RAILS_ROOT)
56
@_env ||= ActiveSupport::StringInquirer.new(RAILS_ENV)
68
@@public_path ||= self.root ? File.join(self.root, "public") : "public"
71
def public_path=(path)
76
# The Initializer is responsible for processing the Rails configuration, such
77
# as setting the $LOAD_PATH, requiring the right frameworks, initializing
78
# logging, and more. It can be run either as a single command that'll just
79
# use the default configuration, like this:
81
# Rails::Initializer.run
83
# But normally it's more interesting to pass in a custom configuration
84
# through the block running:
86
# Rails::Initializer.run do |config|
87
# config.frameworks -= [ :action_mailer ]
90
# This will use the default configuration options from Rails::Configuration,
91
# but allow for overwriting on select areas.
93
# The Configuration instance used by this Initializer instance.
94
attr_reader :configuration
96
# The set of loaded plugins.
97
attr_reader :loaded_plugins
99
# Whether or not all the gem dependencies have been met
100
attr_reader :gems_dependencies_loaded
102
# Runs the initializer. By default, this will invoke the #process method,
103
# which simply executes all of the initialization routines. Alternately,
104
# you can specify explicitly which initialization routine you want:
106
# Rails::Initializer.run(:set_load_path)
108
# This is useful if you only want the load path initialized, without
109
# incurring the overhead of completely loading the entire environment.
110
def self.run(command = :process, configuration = Configuration.new)
111
yield configuration if block_given?
112
initializer = new configuration
113
initializer.send(command)
117
# Create a new Initializer instance that references the given Configuration
119
def initialize(configuration)
120
@configuration = configuration
124
# Sequentially step through all of the available initialization routines,
125
# in order (view execution order in source).
127
Rails.configuration = configuration
130
install_gem_spec_stubs
136
add_plugin_load_paths
144
initialize_framework_caches
147
initialize_framework_logging
149
initialize_dependency_mechanism
150
initialize_whiny_nils
155
initialize_framework_settings
156
initialize_framework_views
160
add_support_load_paths
162
check_for_unbuilt_gems
167
# pick up any gems that plugins depend on
170
check_gem_dependencies
172
# bail out if gems are missing - note that check_gem_dependencies will have
173
# already called abort() unless $gems_rake_task is set
174
return unless gems_dependencies_loaded
176
load_application_initializers
178
# the framework is now fully initialized
181
# Setup database middleware after initializers have run
182
initialize_database_middleware
184
# Prepare dispatcher callbacks and run 'prepare' callbacks
187
# Routing must be initialized after plugins to allow the former to extend the routes
190
# Observers are loaded after plugins in case Observers or observed models are modified by plugins.
193
# Load view path cache
196
# Load application classes
197
load_application_classes
199
# Disable dependency loading during request cycle
200
disable_dependency_loading
203
Rails.initialized = true
206
# Check for valid Ruby version
207
# This is done in an external file, so we can use it
208
# from the `rails` program as well without duplication.
209
def check_ruby_version
210
require 'ruby_version_check'
213
# If Rails is vendored and RubyGems is available, install stub GemSpecs
214
# for Rails, Active Support, Active Record, Action Pack, Action Mailer, and
215
# Active Resource. This allows Gem plugins to depend on Rails even when
216
# the Gem version of Rails shouldn't be loaded.
217
def install_gem_spec_stubs
218
unless Rails.respond_to?(:vendor_rails?)
219
abort %{Your config/boot.rb is outdated: Run "rake rails:update".}
222
if Rails.vendor_rails?
223
begin; require "rubygems"; rescue LoadError; return; end
225
stubs = %w(rails activesupport activerecord actionpack actionmailer activeresource)
226
stubs.reject! { |s| Gem.loaded_specs.key?(s) }
229
Gem.loaded_specs[stub] = Gem::Specification.new do |s|
231
s.version = Rails::VERSION::STRING
238
# Set the <tt>$LOAD_PATH</tt> based on the value of
239
# Configuration#load_paths. Duplicates are removed.
241
load_paths = configuration.load_paths + configuration.framework_paths
242
load_paths.reverse_each { |dir| $LOAD_PATH.unshift(dir) if File.directory?(dir) }
246
# Set the paths from which Rails will automatically load source files, and
247
# the load_once paths.
248
def set_autoload_paths
249
ActiveSupport::Dependencies.load_paths = configuration.load_paths.uniq
250
ActiveSupport::Dependencies.load_once_paths = configuration.load_once_paths.uniq
252
extra = ActiveSupport::Dependencies.load_once_paths - ActiveSupport::Dependencies.load_paths
255
load_once_paths must be a subset of the load_paths.
256
Extra items in load_once_paths: #{extra * ','}
260
# Freeze the arrays so future modifications will fail rather than do nothing mysteriously
261
configuration.load_once_paths.freeze
264
# Requires all frameworks specified by the Configuration#frameworks
265
# list. By default, all frameworks (Active Record, Active Support,
266
# Action Pack, Action Mailer, and Active Resource) are loaded.
267
def require_frameworks
268
configuration.frameworks.each { |framework| require(framework.to_s) }
269
rescue LoadError => e
270
# Re-raise as RuntimeError because Mongrel would swallow LoadError.
274
# Preload all frameworks specified by the Configuration#frameworks.
275
# Used by Passenger to ensure everything's loaded before forking and
276
# to avoid autoload race conditions in JRuby.
277
def preload_frameworks
278
if configuration.preload_frameworks
279
configuration.frameworks.each do |framework|
280
# String#classify and #constantize aren't available yet.
281
toplevel = Object.const_get(framework.to_s.gsub(/(?:^|_)(.)/) { $1.upcase })
282
toplevel.load_all! if toplevel.respond_to?(:load_all!)
287
# Add the load paths used by support functions such as the info controller
288
def add_support_load_paths
291
# Adds all load paths from plugins to the global set of load paths, so that
292
# code from plugins can be required (explicitly or automatically via ActiveSupport::Dependencies).
293
def add_plugin_load_paths
294
plugin_loader.add_plugin_load_paths
297
def add_gem_load_paths
298
Rails::GemDependency.add_frozen_gem_path
299
unless @configuration.gems.empty?
301
@configuration.gems.each { |gem| gem.add_load_paths }
306
unless $gems_rake_task
307
@configuration.gems.each { |gem| gem.load }
311
def check_for_unbuilt_gems
312
unbuilt_gems = @configuration.gems.select(&:frozen?).reject(&:built?)
313
if unbuilt_gems.size > 0
314
# don't print if the gems:build rake tasks are being run
315
unless $gems_build_rake_task
317
The following gems have native components that need to be built
318
#{unbuilt_gems.map { |gem| "#{gem.name} #{gem.requirement}" } * "\n "}
321
ruby #{Gem.ruby_version} at #{Gem.ruby}
322
rubygems #{Gem::RubyGemsVersion} at #{Gem.path * ', '}
324
Run `rake gems:build` to build the unbuilt gems.
330
def check_gem_dependencies
331
unloaded_gems = @configuration.gems.reject { |g| g.loaded? }
332
if unloaded_gems.size > 0
333
@gems_dependencies_loaded = false
334
# don't print if the gems rake tasks are being run
335
unless $gems_rake_task
337
Missing these required gems:
338
#{unloaded_gems.map { |gem| "#{gem.name} #{gem.requirement}" } * "\n "}
341
ruby #{Gem.ruby_version} at #{Gem.ruby}
342
rubygems #{Gem::RubyGemsVersion} at #{Gem.path * ', '}
344
Run `rake gems:install` to install the missing gems.
348
@gems_dependencies_loaded = true
352
# Loads all plugins in <tt>config.plugin_paths</tt>. <tt>plugin_paths</tt>
353
# defaults to <tt>vendor/plugins</tt> but may also be set to a list of
355
# config.plugin_paths = ["#{RAILS_ROOT}/lib/plugins", "#{RAILS_ROOT}/vendor/plugins"]
357
# In the default implementation, as each plugin discovered in <tt>plugin_paths</tt> is initialized:
358
# * its +lib+ directory, if present, is added to the load path (immediately after the applications lib directory)
359
# * <tt>init.rb</tt> is evaluated, if present
361
# After all plugins are loaded, duplicates are removed from the load path.
362
# If an array of plugin names is specified in config.plugins, only those plugins will be loaded
363
# and they plugins will be loaded in that order. Otherwise, plugins are loaded in alphabetical
366
# if config.plugins ends contains :all then the named plugins will be loaded in the given order and all other
367
# plugins will be loaded in alphabetical order
369
plugin_loader.load_plugins
373
@plugin_loader ||= configuration.plugin_loader.new(self)
376
# Loads the environment specified by Configuration#environment_path, which
377
# is typically one of development, test, or production.
380
return if @environment_loaded
381
@environment_loaded = true
383
config = configuration
384
constants = self.class.constants
386
eval(IO.read(configuration.environment_path), binding, configuration.environment_path)
388
(self.class.constants - constants).each do |const|
389
Object.const_set(const, self.class.const_get(const))
395
if gems_dependencies_loaded && configuration.frameworks.include?(:active_record)
396
ActiveRecord::Base.instantiate_observers
401
if configuration.frameworks.include?(:action_view)
402
ActionController::Base.view_paths.load! if configuration.frameworks.include?(:action_controller)
403
ActionMailer::Base.view_paths.load! if configuration.frameworks.include?(:action_mailer)
407
# Eager load application classes
408
def load_application_classes
409
return if $rails_rake_task
410
if configuration.cache_classes
411
configuration.eager_load_paths.each do |load_path|
412
matcher = /\A#{Regexp.escape(load_path)}(.*)\.rb\Z/
413
Dir.glob("#{load_path}/**/*.rb").sort.each do |file|
414
require_dependency file.sub(matcher, '\1')
420
# For Ruby 1.8, this initialization sets $KCODE to 'u' to enable the
421
# multibyte safe operations. Plugin authors supporting other encodings
422
# should override this behaviour and set the relevant +default_charset+
423
# on ActionController::Base.
425
# For Ruby 1.9, this does nothing. Specify the default encoding in the Ruby
426
# shebang line if you don't want UTF-8.
427
def initialize_encoding
428
$KCODE='u' if RUBY_VERSION < '1.9'
431
# This initialization routine does nothing unless <tt>:active_record</tt>
432
# is one of the frameworks to load (Configuration#frameworks). If it is,
433
# this sets the database configuration from Configuration#database_configuration
434
# and then establishes the connection.
435
def initialize_database
436
if configuration.frameworks.include?(:active_record)
437
ActiveRecord::Base.configurations = configuration.database_configuration
438
ActiveRecord::Base.establish_connection
442
def initialize_database_middleware
443
if configuration.frameworks.include?(:active_record)
444
if configuration.frameworks.include?(:action_controller) &&
445
ActionController::Base.session_store.name == 'ActiveRecord::SessionStore'
446
configuration.middleware.insert_before :"ActiveRecord::SessionStore", ActiveRecord::ConnectionAdapters::ConnectionManagement
447
configuration.middleware.insert_before :"ActiveRecord::SessionStore", ActiveRecord::QueryCache
449
configuration.middleware.use ActiveRecord::ConnectionAdapters::ConnectionManagement
450
configuration.middleware.use ActiveRecord::QueryCache
456
unless defined?(RAILS_CACHE)
457
silence_warnings { Object.const_set "RAILS_CACHE", ActiveSupport::Cache.lookup_store(configuration.cache_store) }
459
if RAILS_CACHE.respond_to?(:middleware)
460
# Insert middleware to setup and teardown local cache for each request
461
configuration.middleware.insert_after(:"ActionController::Failsafe", RAILS_CACHE.middleware)
466
def initialize_framework_caches
467
if configuration.frameworks.include?(:action_controller)
468
ActionController::Base.cache_store ||= RAILS_CACHE
472
# If the RAILS_DEFAULT_LOGGER constant is already set, this initialization
473
# routine does nothing. If the constant is not set, and Configuration#logger
474
# is not +nil+, this also does nothing. Otherwise, a new logger instance
475
# is created at Configuration#log_path, with a default log level of
476
# Configuration#log_level.
478
# If the log could not be created, the log will be set to output to
479
# +STDERR+, with a log level of +WARN+.
480
def initialize_logger
481
# if the environment has explicitly defined a logger, use it
482
return if Rails.logger
484
unless logger = configuration.logger
486
logger = ActiveSupport::BufferedLogger.new(configuration.log_path)
487
logger.level = ActiveSupport::BufferedLogger.const_get(configuration.log_level.to_s.upcase)
488
if configuration.environment == "production"
489
logger.auto_flushing = false
491
rescue StandardError => e
492
logger = ActiveSupport::BufferedLogger.new(STDERR)
493
logger.level = ActiveSupport::BufferedLogger::WARN
495
"Rails Error: Unable to access log file. Please ensure that #{configuration.log_path} exists and is chmod 0666. " +
496
"The log level has been raised to WARN and the output directed to STDERR until the problem is fixed."
501
silence_warnings { Object.const_set "RAILS_DEFAULT_LOGGER", logger }
504
# Sets the logger for Active Record, Action Controller, and Action Mailer
505
# (but only for those frameworks that are to be loaded). If the framework's
506
# logger is already set, it is not changed, otherwise it is set to use
507
# RAILS_DEFAULT_LOGGER.
508
def initialize_framework_logging
509
for framework in ([ :active_record, :action_controller, :action_mailer ] & configuration.frameworks)
510
framework.to_s.camelize.constantize.const_get("Base").logger ||= Rails.logger
513
ActiveSupport::Dependencies.logger ||= Rails.logger
514
Rails.cache.logger ||= Rails.logger
517
# Sets +ActionController::Base#view_paths+ and +ActionMailer::Base#template_root+
518
# (but only for those frameworks that are to be loaded). If the framework's
519
# paths have already been set, it is not changed, otherwise it is
520
# set to use Configuration#view_path.
521
def initialize_framework_views
522
if configuration.frameworks.include?(:action_view)
523
view_path = ActionView::PathSet.type_cast(configuration.view_path)
524
ActionMailer::Base.template_root = view_path if configuration.frameworks.include?(:action_mailer) && ActionMailer::Base.view_paths.blank?
525
ActionController::Base.view_paths = view_path if configuration.frameworks.include?(:action_controller) && ActionController::Base.view_paths.blank?
529
# If Action Controller is not one of the loaded frameworks (Configuration#frameworks)
530
# this does nothing. Otherwise, it loads the routing definitions and sets up
531
# loading module used to lazily load controllers (Configuration#controller_paths).
532
def initialize_routing
533
return unless configuration.frameworks.include?(:action_controller)
535
ActionController::Routing.controller_paths += configuration.controller_paths
536
ActionController::Routing::Routes.add_configuration_file(configuration.routes_configuration_file)
537
ActionController::Routing::Routes.reload!
540
# Sets the dependency loading mechanism based on the value of
541
# Configuration#cache_classes.
542
def initialize_dependency_mechanism
543
ActiveSupport::Dependencies.mechanism = configuration.cache_classes ? :require : :load
546
# Loads support for "whiny nil" (noisy warnings when methods are invoked
547
# on +nil+ values) if Configuration#whiny_nils is true.
548
def initialize_whiny_nils
549
require('active_support/whiny_nil') if configuration.whiny_nils
552
# Sets the default value for Time.zone, and turns on ActiveRecord::Base#time_zone_aware_attributes.
553
# If assigned value cannot be matched to a TimeZone, an exception will be raised.
554
def initialize_time_zone
555
if configuration.time_zone
556
zone_default = Time.__send__(:get_zone, configuration.time_zone)
560
'Value assigned to config.time_zone not recognized.' +
561
'Run "rake -D time" for a list of tasks for finding appropriate time zone names.'
564
Time.zone_default = zone_default
566
if configuration.frameworks.include?(:active_record)
567
ActiveRecord::Base.time_zone_aware_attributes = true
568
ActiveRecord::Base.default_timezone = :utc
573
# Set the i18n configuration from config.i18n but special-case for the load_path which should be
574
# appended to what's already set instead of overwritten.
576
configuration.i18n.each do |setting, value|
577
if setting == :load_path
578
I18n.load_path += value
580
I18n.send("#{setting}=", value)
586
Rails::Rack::Metal.requested_metals = configuration.metals
587
Rails::Rack::Metal.metal_paths += plugin_loader.engine_metal_paths
589
configuration.middleware.insert_before(
590
:"ActionController::ParamsParser",
591
Rails::Rack::Metal, :if => Rails::Rack::Metal.metals.any?)
594
# Initializes framework-specific settings for each of the loaded frameworks
595
# (Configuration#frameworks). The available settings map to the accessors
596
# on each of the corresponding Base classes.
597
def initialize_framework_settings
598
configuration.frameworks.each do |framework|
599
base_class = framework.to_s.camelize.constantize.const_get("Base")
601
configuration.send(framework).each do |setting, value|
602
base_class.send("#{setting}=", value)
605
configuration.active_support.each do |setting, value|
606
ActiveSupport.send("#{setting}=", value)
610
# Fires the user-supplied after_initialize block (Configuration#after_initialize)
612
if gems_dependencies_loaded
613
configuration.after_initialize_blocks.each do |block|
619
def load_application_initializers
620
if gems_dependencies_loaded
621
Dir["#{configuration.root_path}/config/initializers/**/*.rb"].sort.each do |initializer|
627
def prepare_dispatcher
628
return unless configuration.frameworks.include?(:action_controller)
629
require 'dispatcher' unless defined?(::Dispatcher)
630
Dispatcher.define_dispatcher_callbacks(configuration.cache_classes)
631
Dispatcher.run_prepare_callbacks
634
def disable_dependency_loading
635
if configuration.cache_classes && !configuration.dependency_loading
636
ActiveSupport::Dependencies.unhook!
641
# The Configuration class holds all the parameters for the Initializer and
642
# ships with defaults that suites most Rails applications. But it's possible
643
# to overwrite everything. Usually, you'll create an Configuration file
644
# implicitly through the block running on the Initializer, but it's also
645
# possible to create the Configuration instance in advance and pass it in
648
# config = Rails::Configuration.new
649
# Rails::Initializer.run(:process, config)
651
# The application's base directory.
652
attr_reader :root_path
654
# A stub for setting options on ActionController::Base.
655
attr_accessor :action_controller
657
# A stub for setting options on ActionMailer::Base.
658
attr_accessor :action_mailer
660
# A stub for setting options on ActionView::Base.
661
attr_accessor :action_view
663
# A stub for setting options on ActiveRecord::Base.
664
attr_accessor :active_record
666
# A stub for setting options on ActiveResource::Base.
667
attr_accessor :active_resource
669
# A stub for setting options on ActiveSupport.
670
attr_accessor :active_support
672
# Whether to preload all frameworks at startup.
673
attr_accessor :preload_frameworks
675
# Whether or not classes should be cached (set to false if you want
676
# application classes to be reloaded on each request)
677
attr_accessor :cache_classes
679
# The list of paths that should be searched for controllers. (Defaults
680
# to <tt>app/controllers</tt>.)
681
attr_accessor :controller_paths
683
# The path to the database configuration file to use. (Defaults to
684
# <tt>config/database.yml</tt>.)
685
attr_accessor :database_configuration_file
687
# The path to the routes configuration file to use. (Defaults to
688
# <tt>config/routes.rb</tt>.)
689
attr_accessor :routes_configuration_file
691
# The list of rails framework components that should be loaded. (Defaults
692
# to <tt>:active_record</tt>, <tt>:action_controller</tt>,
693
# <tt>:action_view</tt>, <tt>:action_mailer</tt>, and
694
# <tt>:active_resource</tt>).
695
attr_accessor :frameworks
697
# An array of additional paths to prepend to the load path. By default,
698
# all +app+, +lib+, +vendor+ and mock paths are included in this list.
699
attr_accessor :load_paths
701
# An array of paths from which Rails will automatically load from only once.
702
# All elements of this array must also be in +load_paths+.
703
attr_accessor :load_once_paths
705
# An array of paths from which Rails will eager load on boot if cache
706
# classes is enabled. All elements of this array must also be in
708
attr_accessor :eager_load_paths
710
# The log level to use for the default Rails logger. In production mode,
711
# this defaults to <tt>:info</tt>. In development mode, it defaults to
713
attr_accessor :log_level
715
# The path to the log file to use. Defaults to log/#{environment}.log
716
# (e.g. log/development.log or log/production.log).
717
attr_accessor :log_path
719
# The specific logger to use. By default, a logger will be created and
720
# initialized using #log_path and #log_level, but a programmer may
721
# specifically set the logger to use via this accessor and it will be
723
attr_accessor :logger
725
# The specific cache store to use. By default, the ActiveSupport::Cache::Store will be used.
726
attr_accessor :cache_store
728
# The root of the application's views. (Defaults to <tt>app/views</tt>.)
729
attr_accessor :view_path
731
# Set to +true+ if you want to be warned (noisily) when you try to invoke
732
# any method of +nil+. Set to +false+ for the standard Ruby behavior.
733
attr_accessor :whiny_nils
735
# The list of plugins to load. If this is set to <tt>nil</tt>, all plugins will
736
# be loaded. If this is set to <tt>[]</tt>, no plugins will be loaded. Otherwise,
737
# plugins will be loaded in the order specified.
739
def plugins=(plugins)
740
@plugins = plugins.nil? ? nil : plugins.map { |p| p.to_sym }
743
# The list of metals to load. If this is set to <tt>nil</tt>, all metals will
744
# be loaded in alphabetical order. If this is set to <tt>[]</tt>, no metals will
745
# be loaded. Otherwise metals will be loaded in the order specified
746
attr_accessor :metals
748
# The path to the root of the plugins directory. By default, it is in
749
# <tt>vendor/plugins</tt>.
750
attr_accessor :plugin_paths
752
# The classes that handle finding the desired plugins that you'd like to load for
753
# your application. By default it is the Rails::Plugin::FileSystemLocator which finds
754
# plugins to load in <tt>vendor/plugins</tt>. You can hook into gem location by subclassing
755
# Rails::Plugin::Locator and adding it onto the list of <tt>plugin_locators</tt>.
756
attr_accessor :plugin_locators
758
# The class that handles loading each plugin. Defaults to Rails::Plugin::Loader, but
759
# a sub class would have access to fine grained modification of the loading behavior. See
760
# the implementation of Rails::Plugin::Loader for more details.
761
attr_accessor :plugin_loader
763
# Enables or disables plugin reloading. You can get around this setting per plugin.
764
# If <tt>reload_plugins?</tt> is false, add this to your plugin's <tt>init.rb</tt>
765
# to make it reloadable:
767
# ActiveSupport::Dependencies.load_once_paths.delete lib_path
769
# If <tt>reload_plugins?</tt> is true, add this to your plugin's <tt>init.rb</tt>
770
# to only load it once:
772
# ActiveSupport::Dependencies.load_once_paths << lib_path
774
attr_accessor :reload_plugins
776
# Returns true if plugin reloading is enabled.
781
# Enables or disables dependency loading during the request cycle. Setting
782
# <tt>dependency_loading</tt> to true will allow new classes to be loaded
783
# during a request. Setting it to false will disable this behavior.
785
# Those who want to run in a threaded environment should disable this
786
# option and eager load or require all there classes on initialization.
788
# If <tt>cache_classes</tt> is disabled, dependency loaded will always be
790
attr_accessor :dependency_loading
792
# An array of gems that this rails application depends on. Rails will automatically load
793
# these gems during installation, and allow you to install any missing gems with:
797
# You can add gems with the #gem method.
800
# Adds a single Gem dependency to the rails application. By default, it will require
801
# the library with the same name as the gem. Use :lib to specify a different name.
803
# # gem 'aws-s3', '>= 0.4.0'
805
# config.gem 'aws-s3', :lib => 'aws/s3', :version => '>= 0.4.0', \
806
# :source => "http://code.whytheluckystiff.net"
808
# To require a library be installed, but not attempt to load it, pass :lib => false
810
# config.gem 'qrp', :version => '0.4.1', :lib => false
811
def gem(name, options = {})
812
@gems << Rails::GemDependency.new(name, options)
815
# Deprecated options:
816
def breakpoint_server(_ = nil)
818
*******************************************************************
819
* config.breakpoint_server has been deprecated and has no effect. *
820
*******************************************************************
823
alias_method :breakpoint_server=, :breakpoint_server
825
# Sets the default +time_zone+. Setting this will enable +time_zone+
826
# awareness for Active Record models and set the Active Record default
827
# timezone to <tt>:utc</tt>.
828
attr_accessor :time_zone
830
# Accessor for i18n settings.
833
# Create a new Configuration instance, initialized with the default
838
self.frameworks = default_frameworks
839
self.load_paths = default_load_paths
840
self.load_once_paths = default_load_once_paths
841
self.eager_load_paths = default_eager_load_paths
842
self.log_path = default_log_path
843
self.log_level = default_log_level
844
self.view_path = default_view_path
845
self.controller_paths = default_controller_paths
846
self.preload_frameworks = default_preload_frameworks
847
self.cache_classes = default_cache_classes
848
self.dependency_loading = default_dependency_loading
849
self.whiny_nils = default_whiny_nils
850
self.plugins = default_plugins
851
self.plugin_paths = default_plugin_paths
852
self.plugin_locators = default_plugin_locators
853
self.plugin_loader = default_plugin_loader
854
self.database_configuration_file = default_database_configuration_file
855
self.routes_configuration_file = default_routes_configuration_file
856
self.gems = default_gems
857
self.i18n = default_i18n
859
for framework in default_frameworks
860
self.send("#{framework}=", Rails::OrderedOptions.new)
862
self.active_support = Rails::OrderedOptions.new
865
# Set the root_path to RAILS_ROOT and canonicalize it.
867
raise 'RAILS_ROOT is not set' unless defined?(::RAILS_ROOT)
868
raise 'RAILS_ROOT is not a directory' unless File.directory?(::RAILS_ROOT)
871
# Pathname is incompatible with Windows, but Windows doesn't have
872
# real symlinks so File.expand_path is safe.
873
if RUBY_PLATFORM =~ /(:?mswin|mingw)/
874
File.expand_path(::RAILS_ROOT)
876
# Otherwise use Pathname#realpath which respects symlinks.
878
Pathname.new(::RAILS_ROOT).realpath.to_s
881
Object.const_set(:RELATIVE_RAILS_ROOT, ::RAILS_ROOT.dup) unless defined?(::RELATIVE_RAILS_ROOT)
882
::RAILS_ROOT.replace @root_path
885
# Enable threaded mode. Allows concurrent requests to controller actions and
886
# multiple database connections. Also disables automatic dependency loading
887
# after boot, and disables reloading code on every request, as these are
888
# fundamentally incompatible with thread safety.
890
self.preload_frameworks = true
891
self.cache_classes = true
892
self.dependency_loading = false
893
self.action_controller.allow_concurrency = true
897
# Loads and returns the contents of the #database_configuration_file. The
898
# contents of the file are processed via ERB before being sent through
900
def database_configuration
902
YAML::load(ERB.new(IO.read(database_configuration_file)).result)
905
# The path to the current environment's file (<tt>development.rb</tt>, etc.). By
906
# default the file is at <tt>config/environments/#{environment}.rb</tt>.
908
"#{root_path}/config/environments/#{environment}.rb"
911
# Return the currently selected environment. By default, it returns the
912
# value of the RAILS_ENV constant.
917
# Adds a block which will be executed after rails has been fully initialized.
918
# Useful for per-environment configuration which depends on the framework being
920
def after_initialize(&after_initialize_block)
921
after_initialize_blocks << after_initialize_block if after_initialize_block
924
# Returns the blocks added with Configuration#after_initialize
925
def after_initialize_blocks
926
@after_initialize_blocks ||= []
929
# Add a preparation callback that will run before every request in development
930
# mode, or before the first request in production.
932
# See Dispatcher#to_prepare.
933
def to_prepare(&callback)
935
require 'dispatcher' unless defined?(::Dispatcher)
936
Dispatcher.to_prepare(&callback)
941
require 'action_controller'
942
ActionController::Dispatcher.middleware
945
def builtin_directories
946
# Include builtins only in the development environment.
947
(environment == 'development') ? Dir["#{RAILTIES_PATH}/builtin/*/"] : []
951
paths = %w(railties railties/lib activesupport/lib)
952
paths << 'actionpack/lib' if frameworks.include?(:action_controller) || frameworks.include?(:action_view)
954
[:active_record, :action_mailer, :active_resource, :action_web_service].each do |framework|
955
paths << "#{framework.to_s.gsub('_', '')}/lib" if frameworks.include?(framework)
958
paths.map { |dir| "#{framework_root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
962
def framework_root_path
963
defined?(::RAILS_FRAMEWORK_ROOT) ? ::RAILS_FRAMEWORK_ROOT : "#{root_path}/vendor/rails"
966
def default_frameworks
967
[ :active_record, :action_controller, :action_view, :action_mailer, :active_resource ]
970
def default_load_paths
973
# Add the old mock paths only if the directories exists
974
paths.concat(Dir["#{root_path}/test/mocks/#{environment}"]) if File.exists?("#{root_path}/test/mocks/#{environment}")
976
# Add the app's controller directory
977
paths.concat(Dir["#{root_path}/app/controllers/"])
979
# Followed by the standard includes.
989
).map { |dir| "#{root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
991
paths.concat builtin_directories
994
# Doesn't matter since plugins aren't in load_paths yet.
995
def default_load_once_paths
999
def default_eager_load_paths
1005
).map { |dir| "#{root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
1008
def default_log_path
1009
File.join(root_path, 'log', "#{environment}.log")
1012
def default_log_level
1013
environment == 'production' ? :info : :debug
1016
def default_database_configuration_file
1017
File.join(root_path, 'config', 'database.yml')
1020
def default_routes_configuration_file
1021
File.join(root_path, 'config', 'routes.rb')
1024
def default_view_path
1025
File.join(root_path, 'app', 'views')
1028
def default_controller_paths
1029
paths = [File.join(root_path, 'app', 'controllers')]
1030
paths.concat builtin_directories
1034
def default_dependency_loading
1038
def default_preload_frameworks
1042
def default_cache_classes
1046
def default_whiny_nils
1054
def default_plugin_paths
1055
["#{root_path}/vendor/plugins"]
1058
def default_plugin_locators
1060
locators << Plugin::GemLocator if defined? Gem
1061
locators << Plugin::FileSystemLocator
1064
def default_plugin_loader
1068
def default_cache_store
1069
if File.exist?("#{root_path}/tmp/cache/")
1070
[ :file_store, "#{root_path}/tmp/cache/" ]
1081
i18n = Rails::OrderedOptions.new
1084
if File.exist?(File.join(RAILS_ROOT, 'config', 'locales'))
1085
i18n.load_path << Dir[File.join(RAILS_ROOT, 'config', 'locales', '*.{rb,yml}')]
1086
i18n.load_path.flatten!
1094
# Needs to be duplicated from Active Support since its needed before Active
1095
# Support is available. Here both Options and Hash are namespaced to prevent
1096
# conflicts with other implementations AND with the classes residing in Active Support.
1097
class Rails::OrderedOptions < Array #:nodoc:
1101
if pair = find_pair(key)
1105
self << [key, value]
1110
pair = find_pair(key.to_sym)
1111
pair ? pair.last : nil
1114
def method_missing(name, *args)
1115
if name.to_s =~ /(.*)=$/
1116
self[$1.to_sym] = args.first
1124
self.each { |i| return i if i.first == key }