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 if defined?(RAILS_ROOT
)
53 require 'active_support/string_inquirer'
54 ActiveSupport
::StringInquirer.new(RAILS_ENV
)
67 @
@public_path ||= self.root
? File
.join(self.root
, "public") : "public"
70 def public_path
=(path
)
75 # The Initializer is responsible for processing the Rails configuration, such
76 # as setting the $LOAD_PATH, requiring the right frameworks, initializing
77 # logging, and more. It can be run either as a single command that'll just
78 # use the default configuration, like this:
80 # Rails::Initializer.run
82 # But normally it's more interesting to pass in a custom configuration
83 # through the block running:
85 # Rails::Initializer.run do |config|
86 # config.frameworks -= [ :action_mailer ]
89 # This will use the default configuration options from Rails::Configuration,
90 # but allow for overwriting on select areas.
92 # The Configuration instance used by this Initializer instance.
93 attr_reader
:configuration
95 # The set of loaded plugins.
96 attr_reader
:loaded_plugins
98 # Whether or not all the gem dependencies have been met
99 attr_reader
:gems_dependencies_loaded
101 # Runs the initializer. By default, this will invoke the #process method,
102 # which simply executes all of the initialization routines. Alternately,
103 # you can specify explicitly which initialization routine you want:
105 # Rails::Initializer.run(:set_load_path)
107 # This is useful if you only want the load path initialized, without
108 # incurring the overhead of completely loading the entire environment.
109 def self.run(command
= :process, configuration
= Configuration
.new
)
110 yield configuration
if block_given
?
111 initializer
= new configuration
112 initializer
.send(command
)
116 # Create a new Initializer instance that references the given Configuration
118 def initialize(configuration
)
119 @configuration = configuration
123 # Sequentially step through all of the available initialization routines,
124 # in order (view execution order in source).
126 Rails
.configuration
= configuration
129 install_gem_spec_stubs
135 add_plugin_load_paths
142 initialize_framework_caches
145 initialize_framework_logging
147 initialize_dependency_mechanism
148 initialize_whiny_nils
149 initialize_temporary_session_directory
154 initialize_framework_settings
155 initialize_framework_views
157 add_support_load_paths
162 # pick up any gems that plugins depend on
165 check_gem_dependencies
167 load_application_initializers
169 # the framework is now fully initialized
172 # Prepare dispatcher callbacks and run 'prepare' callbacks
175 # Routing must be initialized after plugins to allow the former to extend the routes
178 # Observers are loaded after plugins in case Observers or observed models are modified by plugins.
181 # Load view path cache
184 # Load application classes
185 load_application_classes
187 # Disable dependency loading during request cycle
188 disable_dependency_loading
191 Rails
.initialized
= true
194 # Check for valid Ruby version
195 # This is done in an external file, so we can use it
196 # from the `rails` program as well without duplication.
197 def check_ruby_version
198 require 'ruby_version_check'
201 # If Rails is vendored and RubyGems is available, install stub GemSpecs
202 # for Rails, Active Support, Active Record, Action Pack, Action Mailer, and
203 # Active Resource. This allows Gem plugins to depend on Rails even when
204 # the Gem version of Rails shouldn't be loaded.
205 def install_gem_spec_stubs
206 unless Rails
.respond_to
?(:vendor_rails?)
207 abort %
{Your config
/boot
.rb is outdated
: Run
"rake rails:update".}
210 if Rails
.vendor_rails
?
211 begin; require "rubygems"; rescue LoadError
; return; end
213 stubs
= %w(rails activesupport activerecord actionpack actionmailer activeresource
)
214 stubs
.reject
! { |s
| Gem
.loaded_specs
.key
?(s
) }
217 Gem
.loaded_specs
[stub
] = Gem
::Specification.new
do |s
|
219 s
.version = Rails
::VERSION::STRING
226 # Set the <tt>$LOAD_PATH</tt> based on the value of
227 # Configuration#load_paths. Duplicates are removed.
229 load_paths
= configuration
.load_paths
+ configuration
.framework_paths
230 load_paths
.reverse_each
{ |dir
| $LOAD_PATH.unshift(dir
) if File
.directory
?(dir
) }
234 # Set the paths from which Rails will automatically load source files, and
235 # the load_once paths.
236 def set_autoload_paths
237 ActiveSupport
::Dependencies.load_paths
= configuration
.load_paths
.uniq
238 ActiveSupport
::Dependencies.load_once_paths
= configuration
.load_once_paths
.uniq
240 extra
= ActiveSupport
::Dependencies.load_once_paths
- ActiveSupport
::Dependencies.load_paths
243 load_once_paths must be a subset of the load_paths.
244 Extra items in load_once_paths: #{extra * ','}
248 # Freeze the arrays so future modifications will fail rather than do nothing mysteriously
249 configuration
.load_once_paths
.freeze
252 # Requires all frameworks specified by the Configuration#frameworks
253 # list. By default, all frameworks (Active Record, Active Support,
254 # Action Pack, Action Mailer, and Active Resource) are loaded.
255 def require_frameworks
256 configuration
.frameworks
.each
{ |framework
| require(framework
.to_s
) }
257 rescue LoadError
=> e
258 # re-raise because Mongrel would swallow it
262 # Add the load paths used by support functions such as the info controller
263 def add_support_load_paths
266 # Adds all load paths from plugins to the global set of load paths, so that
267 # code from plugins can be required (explicitly or automatically via ActiveSupport::Dependencies).
268 def add_plugin_load_paths
269 plugin_loader
.add_plugin_load_paths
272 def add_gem_load_paths
273 Rails
::GemDependency.add_frozen_gem_path
274 unless @configuration.gems
.empty
?
276 @configuration.gems
.each
{ |gem
| gem
.add_load_paths
}
281 @configuration.gems
.each
{ |gem
| gem
.load
}
284 def check_gem_dependencies
285 unloaded_gems
= @configuration.gems
.reject
{ |g
| g
.loaded
? }
286 if unloaded_gems
.size
> 0
287 @gems_dependencies_loaded = false
288 # don't print if the gems rake tasks are being run
289 unless $rails_gem_installer
291 Missing these required gems:
292 #{unloaded_gems.map { |gem| "#{gem.name} #{gem.requirement}" } * "\n "}
295 ruby #{Gem.ruby_version} at #{Gem.ruby}
296 rubygems #{Gem::RubyGemsVersion} at #{Gem.path * ', '}
298 Run `rake gems:install` to install the missing gems.
302 @gems_dependencies_loaded = true
306 # Loads all plugins in <tt>config.plugin_paths</tt>. <tt>plugin_paths</tt>
307 # defaults to <tt>vendor/plugins</tt> but may also be set to a list of
309 # config.plugin_paths = ["#{RAILS_ROOT}/lib/plugins", "#{RAILS_ROOT}/vendor/plugins"]
311 # In the default implementation, as each plugin discovered in <tt>plugin_paths</tt> is initialized:
312 # * its +lib+ directory, if present, is added to the load path (immediately after the applications lib directory)
313 # * <tt>init.rb</tt> is evaluated, if present
315 # After all plugins are loaded, duplicates are removed from the load path.
316 # If an array of plugin names is specified in config.plugins, only those plugins will be loaded
317 # and they plugins will be loaded in that order. Otherwise, plugins are loaded in alphabetical
320 # if config.plugins ends contains :all then the named plugins will be loaded in the given order and all other
321 # plugins will be loaded in alphabetical order
323 plugin_loader
.load_plugins
327 @plugin_loader ||= configuration
.plugin_loader
.new(self)
330 # Loads the environment specified by Configuration#environment_path, which
331 # is typically one of development, test, or production.
334 return if @environment_loaded
335 @environment_loaded = true
337 config
= configuration
338 constants
= self.class.constants
340 eval(IO
.read(configuration
.environment_path
), binding
, configuration
.environment_path
)
342 (self.class.constants
- constants
).each
do |const
|
343 Object
.const_set(const
, self.class.const_get(const
))
349 if gems_dependencies_loaded
&& configuration
.frameworks
.include?(:active_record)
350 ActiveRecord
::Base.instantiate_observers
355 if configuration
.frameworks
.include?(:action_view)
356 ActionView
::PathSet::Path.eager_load_templates
! if configuration
.cache_classes
357 ActionController
::Base.view_paths
.load
if configuration
.frameworks
.include?(:action_controller)
358 ActionMailer
::Base.template_root
.load
if configuration
.frameworks
.include?(:action_mailer)
362 # Eager load application classes
363 def load_application_classes
364 if configuration
.cache_classes
365 configuration
.eager_load_paths
.each
do |load_path
|
366 matcher
= /\A#{Regexp.escape(load_path)}(.*)\.rb\Z/
367 Dir
.glob("#{load_path}/**/*.rb").sort
.each
do |file
|
368 require_dependency file
.sub(matcher
, '\1')
374 # For Ruby 1.8, this initialization sets $KCODE to 'u' to enable the
375 # multibyte safe operations. Plugin authors supporting other encodings
376 # should override this behaviour and set the relevant +default_charset+
377 # on ActionController::Base.
379 # For Ruby 1.9, this does nothing. Specify the default encoding in the Ruby
380 # shebang line if you don't want UTF-8.
381 def initialize_encoding
382 $KCODE='u' if RUBY_VERSION < '1.9'
385 # This initialization routine does nothing unless <tt>:active_record</tt>
386 # is one of the frameworks to load (Configuration#frameworks). If it is,
387 # this sets the database configuration from Configuration#database_configuration
388 # and then establishes the connection.
389 def initialize_database
390 if configuration
.frameworks
.include?(:active_record)
391 ActiveRecord
::Base.configurations
= configuration
.database_configuration
392 ActiveRecord
::Base.establish_connection
397 unless defined?(RAILS_CACHE
)
398 silence_warnings
{ Object
.const_set
"RAILS_CACHE", ActiveSupport
::Cache.lookup_store(configuration
.cache_store
) }
402 def initialize_framework_caches
403 if configuration
.frameworks
.include?(:action_controller)
404 ActionController
::Base.cache_store
||= RAILS_CACHE
408 # If the RAILS_DEFAULT_LOGGER constant is already set, this initialization
409 # routine does nothing. If the constant is not set, and Configuration#logger
410 # is not +nil+, this also does nothing. Otherwise, a new logger instance
411 # is created at Configuration#log_path, with a default log level of
412 # Configuration#log_level.
414 # If the log could not be created, the log will be set to output to
415 # +STDERR+, with a log level of +WARN+.
416 def initialize_logger
417 # if the environment has explicitly defined a logger, use it
418 return if Rails
.logger
420 unless logger
= configuration
.logger
422 logger
= ActiveSupport
::BufferedLogger.new(configuration
.log_path
)
423 logger
.level
= ActiveSupport
::BufferedLogger.const_get(configuration
.log_level
.to_s
.upcase
)
424 if configuration
.environment
== "production"
425 logger
.auto_flushing
= false
427 rescue StandardError
=> e
428 logger
= ActiveSupport
::BufferedLogger.new(STDERR)
429 logger
.level
= ActiveSupport
::BufferedLogger::WARN
431 "Rails Error: Unable to access log file. Please ensure that #{configuration.log_path} exists and is chmod 0666. " +
432 "The log level has been raised to WARN and the output directed to STDERR until the problem is fixed."
437 silence_warnings
{ Object
.const_set
"RAILS_DEFAULT_LOGGER", logger
}
440 # Sets the logger for Active Record, Action Controller, and Action Mailer
441 # (but only for those frameworks that are to be loaded). If the framework's
442 # logger is already set, it is not changed, otherwise it is set to use
443 # RAILS_DEFAULT_LOGGER.
444 def initialize_framework_logging
445 for framework
in ([ :active_record, :action_controller, :action_mailer ] & configuration
.frameworks
)
446 framework
.to_s
.camelize
.constantize
.const_get("Base").logger
||= Rails
.logger
449 ActiveSupport
::Dependencies.logger
||= Rails
.logger
450 Rails
.cache
.logger
||= Rails
.logger
453 # Sets +ActionController::Base#view_paths+ and +ActionMailer::Base#template_root+
454 # (but only for those frameworks that are to be loaded). If the framework's
455 # paths have already been set, it is not changed, otherwise it is
456 # set to use Configuration#view_path.
457 def initialize_framework_views
458 if configuration
.frameworks
.include?(:action_view)
459 view_path
= ActionView
::PathSet::Path.new(configuration
.view_path
, false)
460 ActionMailer
::Base.template_root
||= view_path
if configuration
.frameworks
.include?(:action_mailer)
461 ActionController
::Base.view_paths
= view_path
if configuration
.frameworks
.include?(:action_controller) && ActionController
::Base.view_paths
.empty
?
465 # If Action Controller is not one of the loaded frameworks (Configuration#frameworks)
466 # this does nothing. Otherwise, it loads the routing definitions and sets up
467 # loading module used to lazily load controllers (Configuration#controller_paths).
468 def initialize_routing
469 return unless configuration
.frameworks
.include?(:action_controller)
470 ActionController
::Routing.controller_paths
= configuration
.controller_paths
471 ActionController
::Routing::Routes.configuration_file
= configuration
.routes_configuration_file
472 ActionController
::Routing::Routes.reload
475 # Sets the dependency loading mechanism based on the value of
476 # Configuration#cache_classes.
477 def initialize_dependency_mechanism
478 ActiveSupport
::Dependencies.mechanism
= configuration
.cache_classes
? :require : :load
481 # Loads support for "whiny nil" (noisy warnings when methods are invoked
482 # on +nil+ values) if Configuration#whiny_nils is true.
483 def initialize_whiny_nils
484 require('active_support/whiny_nil') if configuration
.whiny_nils
487 def initialize_temporary_session_directory
488 if configuration
.frameworks
.include?(:action_controller)
489 session_path
= "#{configuration.root_path}/tmp/sessions/"
490 ActionController
::Base.session_options
[:tmpdir] = File
.exist
?(session_path
) ? session_path
: Dir
::tmpdir
494 # Sets the default value for Time.zone, and turns on ActiveRecord::Base#time_zone_aware_attributes.
495 # If assigned value cannot be matched to a TimeZone, an exception will be raised.
496 def initialize_time_zone
497 if configuration
.time_zone
498 zone_default
= Time
.__send__(:get_zone, configuration
.time_zone
)
500 raise %{Value assigned to config
.time_zone
not recognized
. Run
"rake -D time" for a list of tasks
for finding appropriate time zone names
.}
502 Time
.zone_default
= zone_default
503 if configuration
.frameworks
.include?(:active_record)
504 ActiveRecord
::Base.time_zone_aware_attributes
= true
505 ActiveRecord
::Base.default_timezone
= :utc
510 # Set the i18n configuration from config.i18n but special-case for the load_path which should be
511 # appended to what's already set instead of overwritten.
513 configuration
.i18n
.each
do |setting
, value
|
514 if setting
== :load_path
515 I18n
.load_path
+= value
517 I18n
.send("#{setting}=", value
)
522 # Initializes framework-specific settings for each of the loaded frameworks
523 # (Configuration#frameworks). The available settings map to the accessors
524 # on each of the corresponding Base classes.
525 def initialize_framework_settings
526 configuration
.frameworks
.each
do |framework
|
527 base_class
= framework
.to_s
.camelize
.constantize
.const_get("Base")
529 configuration
.send(framework
).each
do |setting
, value
|
530 base_class
.send("#{setting}=", value
)
533 configuration
.active_support
.each
do |setting
, value
|
534 ActiveSupport
.send("#{setting}=", value
)
538 # Fires the user-supplied after_initialize block (Configuration#after_initialize)
540 if gems_dependencies_loaded
541 configuration
.after_initialize_blocks
.each
do |block
|
547 def load_application_initializers
548 if gems_dependencies_loaded
549 Dir
["#{configuration.root_path}/config/initializers/**/*.rb"].sort
.each
do |initializer
|
555 def prepare_dispatcher
556 return unless configuration
.frameworks
.include?(:action_controller)
557 require 'dispatcher' unless defined?(::Dispatcher)
558 Dispatcher
.define_dispatcher_callbacks(configuration
.cache_classes
)
559 Dispatcher
.new(Rails
.logger
).send
:run_callbacks, :prepare_dispatch
562 def disable_dependency_loading
563 if configuration
.cache_classes
&& !configuration
.dependency_loading
564 ActiveSupport
::Dependencies.unhook
!
569 # The Configuration class holds all the parameters for the Initializer and
570 # ships with defaults that suites most Rails applications. But it's possible
571 # to overwrite everything. Usually, you'll create an Configuration file
572 # implicitly through the block running on the Initializer, but it's also
573 # possible to create the Configuration instance in advance and pass it in
576 # config = Rails::Configuration.new
577 # Rails::Initializer.run(:process, config)
579 # The application's base directory.
580 attr_reader
:root_path
582 # A stub for setting options on ActionController::Base.
583 attr_accessor
:action_controller
585 # A stub for setting options on ActionMailer::Base.
586 attr_accessor
:action_mailer
588 # A stub for setting options on ActionView::Base.
589 attr_accessor
:action_view
591 # A stub for setting options on ActiveRecord::Base.
592 attr_accessor
:active_record
594 # A stub for setting options on ActiveResource::Base.
595 attr_accessor
:active_resource
597 # A stub for setting options on ActiveSupport.
598 attr_accessor
:active_support
600 # Whether or not classes should be cached (set to false if you want
601 # application classes to be reloaded on each request)
602 attr_accessor
:cache_classes
604 # The list of paths that should be searched for controllers. (Defaults
605 # to <tt>app/controllers</tt> and <tt>components</tt>.)
606 attr_accessor
:controller_paths
608 # The path to the database configuration file to use. (Defaults to
609 # <tt>config/database.yml</tt>.)
610 attr_accessor
:database_configuration_file
612 # The path to the routes configuration file to use. (Defaults to
613 # <tt>config/routes.rb</tt>.)
614 attr_accessor
:routes_configuration_file
616 # The list of rails framework components that should be loaded. (Defaults
617 # to <tt>:active_record</tt>, <tt>:action_controller</tt>,
618 # <tt>:action_view</tt>, <tt>:action_mailer</tt>, and
619 # <tt>:active_resource</tt>).
620 attr_accessor
:frameworks
622 # An array of additional paths to prepend to the load path. By default,
623 # all +app+, +lib+, +vendor+ and mock paths are included in this list.
624 attr_accessor
:load_paths
626 # An array of paths from which Rails will automatically load from only once.
627 # All elements of this array must also be in +load_paths+.
628 attr_accessor
:load_once_paths
630 # An array of paths from which Rails will eager load on boot if cache
631 # classes is enabled. All elements of this array must also be in
633 attr_accessor
:eager_load_paths
635 # The log level to use for the default Rails logger. In production mode,
636 # this defaults to <tt>:info</tt>. In development mode, it defaults to
638 attr_accessor
:log_level
640 # The path to the log file to use. Defaults to log/#{environment}.log
641 # (e.g. log/development.log or log/production.log).
642 attr_accessor
:log_path
644 # The specific logger to use. By default, a logger will be created and
645 # initialized using #log_path and #log_level, but a programmer may
646 # specifically set the logger to use via this accessor and it will be
648 attr_accessor
:logger
650 # The specific cache store to use. By default, the ActiveSupport::Cache::Store will be used.
651 attr_accessor
:cache_store
653 # The root of the application's views. (Defaults to <tt>app/views</tt>.)
654 attr_accessor
:view_path
656 # Set to +true+ if you want to be warned (noisily) when you try to invoke
657 # any method of +nil+. Set to +false+ for the standard Ruby behavior.
658 attr_accessor
:whiny_nils
660 # The list of plugins to load. If this is set to <tt>nil</tt>, all plugins will
661 # be loaded. If this is set to <tt>[]</tt>, no plugins will be loaded. Otherwise,
662 # plugins will be loaded in the order specified.
664 def plugins
=(plugins
)
665 @plugins = plugins
.nil? ? nil : plugins
.map
{ |p
| p
.to_sym
}
668 # The path to the root of the plugins directory. By default, it is in
669 # <tt>vendor/plugins</tt>.
670 attr_accessor
:plugin_paths
672 # The classes that handle finding the desired plugins that you'd like to load for
673 # your application. By default it is the Rails::Plugin::FileSystemLocator which finds
674 # plugins to load in <tt>vendor/plugins</tt>. You can hook into gem location by subclassing
675 # Rails::Plugin::Locator and adding it onto the list of <tt>plugin_locators</tt>.
676 attr_accessor
:plugin_locators
678 # The class that handles loading each plugin. Defaults to Rails::Plugin::Loader, but
679 # a sub class would have access to fine grained modification of the loading behavior. See
680 # the implementation of Rails::Plugin::Loader for more details.
681 attr_accessor
:plugin_loader
683 # Enables or disables plugin reloading. You can get around this setting per plugin.
684 # If <tt>reload_plugins?</tt> is false, add this to your plugin's <tt>init.rb</tt>
685 # to make it reloadable:
687 # ActiveSupport::Dependencies.load_once_paths.delete lib_path
689 # If <tt>reload_plugins?</tt> is true, add this to your plugin's <tt>init.rb</tt>
690 # to only load it once:
692 # ActiveSupport::Dependencies.load_once_paths << lib_path
694 attr_accessor
:reload_plugins
696 # Returns true if plugin reloading is enabled.
701 # Enables or disables dependency loading during the request cycle. Setting
702 # <tt>dependency_loading</tt> to true will allow new classes to be loaded
703 # during a request. Setting it to false will disable this behavior.
705 # Those who want to run in a threaded environment should disable this
706 # option and eager load or require all there classes on initialization.
708 # If <tt>cache_classes</tt> is disabled, dependency loaded will always be
710 attr_accessor
:dependency_loading
712 # An array of gems that this rails application depends on. Rails will automatically load
713 # these gems during installation, and allow you to install any missing gems with:
717 # You can add gems with the #gem method.
720 # Adds a single Gem dependency to the rails application. By default, it will require
721 # the library with the same name as the gem. Use :lib to specify a different name.
723 # # gem 'aws-s3', '>= 0.4.0'
725 # config.gem 'aws-s3', :lib => 'aws/s3', :version => '>= 0.4.0', \
726 # :source => "http://code.whytheluckystiff.net"
728 # To require a library be installed, but not attempt to load it, pass :lib => false
730 # config.gem 'qrp', :version => '0.4.1', :lib => false
731 def gem(name
, options
= {})
732 @gems << Rails
::GemDependency.new(name
, options
)
735 # Deprecated options:
736 def breakpoint_server(_
= nil)
738 *******************************************************************
739 * config.breakpoint_server has been deprecated and has no effect. *
740 *******************************************************************
743 alias_method :breakpoint_server=, :breakpoint_server
745 # Sets the default +time_zone+. Setting this will enable +time_zone+
746 # awareness for Active Record models and set the Active Record default
747 # timezone to <tt>:utc</tt>.
748 attr_accessor :time_zone
750 # Accessor for i18n settings.
753 # Create a new Configuration instance, initialized with the default
758 self.frameworks = default_frameworks
759 self.load_paths = default_load_paths
760 self.load_once_paths = default_load_once_paths
761 self.eager_load_paths = default_eager_load_paths
762 self.log_path = default_log_path
763 self.log_level = default_log_level
764 self.view_path = default_view_path
765 self.controller_paths = default_controller_paths
766 self.cache_classes = default_cache_classes
767 self.dependency_loading = default_dependency_loading
768 self.whiny_nils = default_whiny_nils
769 self.plugins = default_plugins
770 self.plugin_paths = default_plugin_paths
771 self.plugin_locators = default_plugin_locators
772 self.plugin_loader = default_plugin_loader
773 self.database_configuration_file = default_database_configuration_file
774 self.routes_configuration_file = default_routes_configuration_file
775 self.gems = default_gems
776 self.i18n = default_i18n
778 for framework in default_frameworks
779 self.send("#{framework}=", Rails::OrderedOptions.new)
781 self.active_support = Rails::OrderedOptions.new
784 # Set the root_path to RAILS_ROOT and canonicalize it.
786 raise 'RAILS_ROOT is not set' unless defined?(::RAILS_ROOT)
787 raise 'RAILS_ROOT is not a directory' unless File.directory?(::RAILS_ROOT)
790 # Pathname is incompatible with Windows, but Windows doesn't have
791 # real symlinks so File.expand_path is safe.
792 if RUBY_PLATFORM =~ /(:?mswin|mingw)/
793 File.expand_path(::RAILS_ROOT)
795 # Otherwise use Pathname#realpath which respects symlinks.
797 Pathname.new(::RAILS_ROOT).realpath.to_s
800 Object.const_set(:RELATIVE_RAILS_ROOT, ::RAILS_ROOT.dup) unless defined?(::RELATIVE_RAILS_ROOT)
801 ::RAILS_ROOT.replace @root_path
804 # Enable threaded mode. Allows concurrent requests to controller actions and
805 # multiple database connections. Also disables automatic dependency loading
808 self.cache_classes = true
809 self.dependency_loading = false
810 self.action_controller.allow_concurrency = true
814 # Loads and returns the contents of the #database_configuration_file. The
815 # contents of the file are processed via ERB before being sent through
817 def database_configuration
819 YAML::load(ERB.new(IO.read(database_configuration_file)).result)
822 # The path to the current environment's file (<tt>development.rb</tt>, etc.). By
823 # default the file is at <tt>config/environments/#{environment}.rb</tt>.
825 "#{root_path}/config/environments/#{environment}.rb"
828 # Return the currently selected environment. By default, it returns the
829 # value of the RAILS_ENV constant.
834 # Adds a block which will be executed after rails has been fully initialized.
835 # Useful for per-environment configuration which depends on the framework being
837 def after_initialize(&after_initialize_block)
838 after_initialize_blocks << after_initialize_block if after_initialize_block
841 # Returns the blocks added with Configuration#after_initialize
842 def after_initialize_blocks
843 @after_initialize_blocks ||= []
846 # Add a preparation callback that will run before every request in development
847 # mode, or before the first request in production.
849 # See Dispatcher#to_prepare.
850 def to_prepare(&callback)
852 require 'dispatcher' unless defined?(::Dispatcher)
853 Dispatcher.to_prepare(&callback)
857 def builtin_directories
858 # Include builtins only in the development environment.
859 (environment == 'development') ? Dir["#{RAILTIES_PATH}/builtin/*/"] : []
863 paths = %w(railties railties/lib activesupport/lib)
864 paths << 'actionpack/lib' if frameworks.include? :action_controller or frameworks.include? :action_view
866 [:active_record, :action_mailer, :active_resource, :action_web_service].each do |framework|
867 paths << "#{framework.to_s.gsub('_', '')}/lib" if frameworks.include? framework
870 paths.map { |dir| "#{framework_root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
874 def framework_root_path
875 defined?(::RAILS_FRAMEWORK_ROOT) ? ::RAILS_FRAMEWORK_ROOT : "#{root_path}/vendor/rails"
878 def default_frameworks
879 [ :active_record, :action_controller, :action_view, :action_mailer, :active_resource ]
882 def default_load_paths
885 # Add the old mock paths only if the directories exists
886 paths.concat(Dir["#{root_path}/test/mocks/#{environment}"]) if File.exists?("#{root_path}/test/mocks/#{environment}")
888 # Add the app's controller directory
889 paths.concat(Dir["#{root_path}/app/controllers/"])
891 # Then components subdirectories.
892 paths.concat(Dir["#{root_path}/components/[_a-z]*"])
894 # Followed by the standard includes.
905 ).map { |dir| "#{root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
907 paths.concat builtin_directories
910 # Doesn't matter since plugins aren't in load_paths yet.
911 def default_load_once_paths
915 def default_eager_load_paths
920 ).map { |dir| "#{root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
924 File.join(root_path, 'log', "#{environment}.log")
927 def default_log_level
928 environment == 'production' ? :info : :debug
931 def default_database_configuration_file
932 File.join(root_path, 'config', 'database.yml')
935 def default_routes_configuration_file
936 File.join(root_path, 'config', 'routes.rb')
939 def default_view_path
940 File.join(root_path, 'app', 'views')
943 def default_controller_paths
944 paths = [File.join(root_path, 'app', 'controllers')]
945 paths.concat builtin_directories
949 def default_dependency_loading
953 def default_cache_classes
957 def default_whiny_nils
965 def default_plugin_paths
966 ["#{root_path}/vendor/plugins"]
969 def default_plugin_locators
971 locators << Plugin::GemLocator if defined? Gem
972 locators << Plugin::FileSystemLocator
975 def default_plugin_loader
979 def default_cache_store
980 if File.exist?("#{root_path}/tmp/cache/")
981 [ :file_store, "#{root_path}/tmp/cache/" ]
992 i18n = Rails::OrderedOptions.new
995 if File.exist?(File.join(RAILS_ROOT, 'config', 'locales'))
996 i18n.load_path << Dir[File.join(RAILS_ROOT, 'config', 'locales', '*.{rb,yml}')]
997 i18n.load_path.flatten!
1005 # Needs to be duplicated from Active Support since its needed before Active
1006 # Support is available. Here both Options and Hash are namespaced to prevent
1007 # conflicts with other implementations AND with the classes residing in Active Support.
1008 class Rails::OrderedOptions < Array #:nodoc:
1012 if pair = find_pair(key)
1016 self << [key, value]
1021 pair = find_pair(key.to_sym)
1022 pair ? pair.last : nil
1025 def method_missing(name, *args)
1026 if name.to_s =~ /(.*)=$/
1027 self[$1.to_sym] = args.first
1035 self.each { |i| return i if i.first == key }