The Configuration class holds all the parameters for the Initializer and ships with defaults that suites most Rails applications. But it’s possible to overwrite everything. Usually, you’ll create an Configuration file implicitly through the block running on the Initializer, but it’s also possible to create the Configuration instance in advance and pass it in like this:
config = Rails::Configuration.new Rails::Initializer.run(:process, config)
- A
- B
- D
- E
- F
- N
- S
- T
[RW] | action_controller | A stub for setting options on ActionController::Base |
[RW] | action_mailer | A stub for setting options on ActionMailer::Base |
[RW] | action_view | A stub for setting options on ActionView::Base |
[RW] | action_web_service | A stub for setting options on ActionWebService::Base |
[RW] | active_record | A stub for setting options on ActiveRecord::Base |
[RW] | breakpoint_server | Whether or not to use the breakpoint server (boolean) |
[RW] | cache_classes | Whether or not classes should be cached (set to false if you want application classes to be reloaded on each request) |
[RW] | connection_adapters | The list of connection adapters to load. (By default, all connection adapters are loaded. You can set this to be just the adapter(s) you will use to reduce your application’s load time.) |
[RW] | controller_paths | The list of paths that should be searched for controllers. (Defaults to
|
[RW] | database_configuration_file | The path to the database configuration file to use. (Defaults to
|
[RW] | frameworks | The list of rails framework components that should be loaded. (Defaults to
|
[RW] | load_once_paths | An array of paths from which Rails will
automatically load from only once. All elements of this array must also be
in |
[RW] | load_paths | An array of additional paths to prepend to the load path. By default, all
|
[RW] | log_level | The log level to use for the default Rails
logger. In production mode, this defaults to |
[RW] | log_path | The path to the log file to use. Defaults to log/#{environment}.log (e.g. log/development.log or log/production.log). |
[RW] | logger | The specific logger to use. By default, a logger will be created and initialized using log_path and log_level, but a programmer may specifically set the logger to use via this accessor and it will be used directly. |
[RW] | plugin_paths | The path to the root of the plugins directory. By default, it is in
|
[RW] | plugins | The list of plugins to load. If this is set to |
[R] | root_path | The application’s base directory. |
[RW] | view_path | The root of the application’s views. (Defaults to |
[RW] | whiny_nils | Set to |
Create a new Configuration instance, initialized with the default values.
Source: show
# File rails/railties/lib/initializer.rb, line 508 def initialize set_root_path! self.frameworks = default_frameworks self.load_paths = default_load_paths self.load_once_paths = default_load_once_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.breakpoint_server = default_breakpoint_server self.whiny_nils = default_whiny_nils self.plugins = default_plugins self.plugin_paths = default_plugin_paths self.database_configuration_file = default_database_configuration_file for framework in default_frameworks self.send("#{framework}=", Rails::OrderedOptions.new) end end
Sets a block which will be executed after rails has been fully initialized. Useful for per-environment configuration which depends on the framework being fully initialized.
Source: show
# File rails/railties/lib/initializer.rb, line 569 def after_initialize(&after_initialize_block) @after_initialize_block = after_initialize_block end
Returns the block set in #after_initialize
Source: show
# File rails/railties/lib/initializer.rb, line 574 def after_initialize_block @after_initialize_block end
Source: show
# File rails/railties/lib/initializer.rb, line 587 def builtin_directories # Include builtins only in the development environment. (environment == 'development') ? Dir["#{RAILTIES_PATH}/builtin/*/"] : [] end
Loads and returns the contents of the database_configuration_file. The contents of the file are processed via ERB before being sent through YAML::load.
Source: show
# File rails/railties/lib/initializer.rb, line 550 def database_configuration YAML::load(ERB.new(IO.read(database_configuration_file)).result) end
Return the currently selected environment. By default, it returns the value
of the RAILS_ENV
constant.
Source: show
# File rails/railties/lib/initializer.rb, line 562 def environment ::RAILS_ENV end
The path to the current environment’s file (development.rb, etc.). By
default the file is at config/environments/#{environment}.rb
.
Source: show
# File rails/railties/lib/initializer.rb, line 556 def environment_path "#{root_path}/config/environments/#{environment}.rb" end
Source: show
# File rails/railties/lib/initializer.rb, line 592 def framework_paths # TODO: Don't include dirs for frameworks that are not used %w( railties railties/lib actionpack/lib activesupport/lib activerecord/lib actionmailer/lib actionwebservice/lib ).map { |dir| "#{framework_root_path}/#{dir}" }.select { |dir| File.directory?(dir) } end
Set the #root_path to RAILS_ROOT and canonicalize it.
Source: show
# File rails/railties/lib/initializer.rb, line 531 def set_root_path! raise 'RAILS_ROOT is not set' unless defined?(::RAILS_ROOT) raise 'RAILS_ROOT is not a directory' unless File.directory?(::RAILS_ROOT) @root_path = # Pathname is incompatible with Windows, but Windows doesn't have # real symlinks so File.expand_path is safe. if RUBY_PLATFORM =~ %r(:?mswin|mingw)/ File.expand_path(::RAILS_ROOT) # Otherwise use Pathname#realpath which respects symlinks. else Pathname.new(::RAILS_ROOT).realpath.to_s end end
Add a preparation callback that will run before every request in development mode, or before the first request in production.
See Dispatcher#to_prepare.
Source: show
# File rails/railties/lib/initializer.rb, line 582 def to_prepare(&callback) require 'dispatcher' unless defined?(::Dispatcher) Dispatcher.to_prepare(&callback) end