Class | Rails::Configuration |
In: |
vendor/rails/railties/lib/initializer.rb
|
Parent: | Object |
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)
action_controller | [RW] | A stub for setting options on ActionController::Base |
action_mailer | [RW] | A stub for setting options on ActionMailer::Base |
action_view | [RW] | A stub for setting options on ActionView::Base |
active_record | [RW] | A stub for setting options on ActiveRecord::Base |
active_resource | [RW] | A stub for setting options on ActiveRecord::Base |
cache_classes | [RW] | Whether or not classes should be cached (set to false if you want application classes to be reloaded on each request) |
controller_paths | [RW] | The list of paths that should be searched for controllers. (Defaults to app/controllers and components.) |
database_configuration_file | [RW] | The path to the database configuration file to use. (Defaults to config/database.yml.) |
frameworks | [RW] | The list of rails framework components that should be loaded. (Defaults to :active_record, :action_controller, :action_view, :action_mailer, and :active_resource). |
load_once_paths | [RW] | An array of paths from which Rails will automatically load from only once. All elements of this array must also be in load_paths. |
load_paths | [RW] | An array of additional paths to prepend to the load path. By default, all app, lib, vendor and mock paths are included in this list. |
log_level | [RW] | The log level to use for the default Rails logger. In production mode, this defaults to :info. In development mode, it defaults to :debug. |
log_path | [RW] | The path to the log file to use. Defaults to log/#{environment}.log (e.g. log/development.log or log/production.log). |
logger | [RW] | 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. |
plugin_loader | [RW] | The class that handles loading each plugin. Defaults to Rails::Plugin::Loader, but a sub class would have access to fine grained modification of the loading behavior. See the implementation of Rails::Plugin::Loader for more details. |
plugin_locators | [RW] | The classes that handle finding the desired plugins that you‘d like to load for your application. By default it is the Rails::Plugin::FileSystemLocator which finds plugins to load in vendor/plugins. You can hook into gem location by subclassing Rails::Plugin::Locator and adding it onto the list of plugin_locators. |
plugin_paths | [RW] | The path to the root of the plugins directory. By default, it is in vendor/plugins. |
plugins | [R] | The list of plugins to load. If this is set to nil, all plugins will be loaded. If this is set to [], no plugins will be loaded. Otherwise, plugins will be loaded in the order specified. |
root_path | [R] | The application‘s base directory. |
view_path | [RW] | The root of the application‘s views. (Defaults to app/views.) |
whiny_nils | [RW] | Set to true if you want to be warned (noisily) when you try to invoke any method of nil. Set to false for the standard Ruby behavior. |
Create a new Configuration instance, initialized with the default values.
# File vendor/rails/railties/lib/initializer.rb, line 460 460: def initialize 461: set_root_path! 462: 463: self.frameworks = default_frameworks 464: self.load_paths = default_load_paths 465: self.load_once_paths = default_load_once_paths 466: self.log_path = default_log_path 467: self.log_level = default_log_level 468: self.view_path = default_view_path 469: self.controller_paths = default_controller_paths 470: self.cache_classes = default_cache_classes 471: self.whiny_nils = default_whiny_nils 472: self.plugins = default_plugins 473: self.plugin_paths = default_plugin_paths 474: self.plugin_locators = default_plugin_locators 475: self.plugin_loader = default_plugin_loader 476: self.database_configuration_file = default_database_configuration_file 477: 478: for framework in default_frameworks 479: self.send("#{framework}=", Rails::OrderedOptions.new) 480: end 481: end
Adds 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.
# File vendor/rails/railties/lib/initializer.rb, line 525 525: def after_initialize(&after_initialize_block) 526: after_initialize_blocks << after_initialize_block if after_initialize_block 527: end
Returns the blocks added with Configuration#after_initialize
# File vendor/rails/railties/lib/initializer.rb, line 530 530: def after_initialize_blocks 531: @after_initialize_blocks ||= [] 532: end
Deprecated options:
# File vendor/rails/railties/lib/initializer.rb, line 449 449: def breakpoint_server(_ = nil) 450: $stderr.puts %( 451: ******************************************************************* 452: * config.breakpoint_server has been deprecated and has no effect. * 453: ******************************************************************* 454: ) 455: end
# File vendor/rails/railties/lib/initializer.rb, line 543 543: def builtin_directories 544: # Include builtins only in the development environment. 545: (environment == 'development') ? Dir["#{RAILTIES_PATH}/builtin/*/"] : [] 546: 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.
# File vendor/rails/railties/lib/initializer.rb, line 506 506: def database_configuration 507: YAML::load(ERB.new(IO.read(database_configuration_file)).result) 508: end
Return the currently selected environment. By default, it returns the value of the RAILS_ENV constant.
# File vendor/rails/railties/lib/initializer.rb, line 518 518: def environment 519: ::RAILS_ENV 520: end
The path to the current environment‘s file (development.rb, etc.). By default the file is at config/environments/#{environment}.rb.
# File vendor/rails/railties/lib/initializer.rb, line 512 512: def environment_path 513: "#{root_path}/config/environments/#{environment}.rb" 514: end
# File vendor/rails/railties/lib/initializer.rb, line 548 548: def framework_paths 549: paths = %w(railties railties/lib activesupport/lib) 550: paths << 'actionpack/lib' if frameworks.include? :action_controller or frameworks.include? :action_view 551: 552: [:active_record, :action_mailer, :active_resource, :action_web_service].each do |framework| 553: paths << "#{framework.to_s.gsub('_', '')}/lib" if frameworks.include? framework 554: end 555: 556: paths.map { |dir| "#{framework_root_path}/#{dir}" }.select { |dir| File.directory?(dir) } 557: end
# File vendor/rails/railties/lib/initializer.rb, line 429 429: def plugins=(plugins) 430: @plugins = plugins.nil? ? nil : plugins.map { |p| p.to_sym } 431: end
Set the root_path to RAILS_ROOT and canonicalize it.
# File vendor/rails/railties/lib/initializer.rb, line 484 484: def set_root_path! 485: raise 'RAILS_ROOT is not set' unless defined?(::RAILS_ROOT) 486: raise 'RAILS_ROOT is not a directory' unless File.directory?(::RAILS_ROOT) 487: 488: @root_path = 489: # Pathname is incompatible with Windows, but Windows doesn't have 490: # real symlinks so File.expand_path is safe. 491: if RUBY_PLATFORM =~ /(:?mswin|mingw)/ 492: File.expand_path(::RAILS_ROOT) 493: 494: # Otherwise use Pathname#realpath which respects symlinks. 495: else 496: Pathname.new(::RAILS_ROOT).realpath.to_s 497: end 498: 499: Object.const_set(:RELATIVE_RAILS_ROOT, ::RAILS_ROOT.dup) unless defined?(::RELATIVE_RAILS_ROOT) 500: ::RAILS_ROOT.replace @root_path 501: 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.
# File vendor/rails/railties/lib/initializer.rb, line 538 538: def to_prepare(&callback) 539: require 'dispatcher' unless defined?(::Dispatcher) 540: Dispatcher.to_prepare(&callback) 541: end