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. |
active_support | [RW] | A stub for setting options on ActiveSupport. |
cache_classes | [RW] | Whether or not classes should be cached (set to false if you want application classes to be reloaded on each request) |
cache_store | [RW] | The specific cache store to use. By default, the ActiveSupport::Cache::Store will be used. |
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). |
gems | [RW] |
An array of gems that this rails application depends on. Rails will automatically load these gems during
installation, and allow you to install any missing gems with:
rake gems:install You can add gems with the gem method. |
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. |
reload_plugins | [RW] |
Enables or disables plugin reloading. You can get around this setting per
plugin. If reload_plugins? is false, add
this to your plugin‘s init.rb to make it reloadable:
Dependencies.load_once_paths.delete lib_path If reload_plugins? is true, add this to your plugin‘s init.rb to only load it once: Dependencies.load_once_paths << lib_path |
root_path | [R] | The application‘s base directory. |
routes_configuration_file | [RW] | The path to the routes configuration file to use. (Defaults to config/routes.rb.) |
time_zone | [RW] | Sets the default time_zone. Setting this will enable time_zone awareness for Active Record models and set the Active Record default timezone to :utc. |
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 652 652: def initialize 653: set_root_path! 654: 655: self.frameworks = default_frameworks 656: self.load_paths = default_load_paths 657: self.load_once_paths = default_load_once_paths 658: self.log_path = default_log_path 659: self.log_level = default_log_level 660: self.view_path = default_view_path 661: self.controller_paths = default_controller_paths 662: self.cache_classes = default_cache_classes 663: self.whiny_nils = default_whiny_nils 664: self.plugins = default_plugins 665: self.plugin_paths = default_plugin_paths 666: self.plugin_locators = default_plugin_locators 667: self.plugin_loader = default_plugin_loader 668: self.database_configuration_file = default_database_configuration_file 669: self.routes_configuration_file = default_routes_configuration_file 670: self.gems = default_gems 671: 672: for framework in default_frameworks 673: self.send("#{framework}=", Rails::OrderedOptions.new) 674: end 675: self.active_support = Rails::OrderedOptions.new 676: 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 720 720: def after_initialize(&after_initialize_block) 721: after_initialize_blocks << after_initialize_block if after_initialize_block 722: end
Returns the blocks added with Configuration#after_initialize
# File vendor/rails/railties/lib/initializer.rb, line 725 725: def after_initialize_blocks 726: @after_initialize_blocks ||= [] 727: end
Deprecated options:
# File vendor/rails/railties/lib/initializer.rb, line 636 636: def breakpoint_server(_ = nil) 637: $stderr.puts %( 638: ******************************************************************* 639: * config.breakpoint_server has been deprecated and has no effect. * 640: ******************************************************************* 641: ) 642: end
# File vendor/rails/railties/lib/initializer.rb, line 740 740: def builtin_directories 741: # Include builtins only in the development environment. 742: (environment == 'development') ? Dir["#{RAILTIES_PATH}/builtin/*/"] : [] 743: 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 701 701: def database_configuration 702: YAML::load(ERB.new(IO.read(database_configuration_file)).result) 703: 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 713 713: def environment 714: ::RAILS_ENV 715: 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 707 707: def environment_path 708: "#{root_path}/config/environments/#{environment}.rb" 709: end
# File vendor/rails/railties/lib/initializer.rb, line 745 745: def framework_paths 746: paths = %w(railties railties/lib activesupport/lib) 747: paths << 'actionpack/lib' if frameworks.include? :action_controller or frameworks.include? :action_view 748: 749: [:active_record, :action_mailer, :active_resource, :action_web_service].each do |framework| 750: paths << "#{framework.to_s.gsub('_', '')}/lib" if frameworks.include? framework 751: end 752: 753: paths.map { |dir| "#{framework_root_path}/#{dir}" }.select { |dir| File.directory?(dir) } 754: end
Adds a single Gem dependency to the rails application.
# gem 'aws-s3', '>= 0.4.0' # require 'aws/s3' config.gem 'aws-s3', :lib => 'aws/s3', :version => '>= 0.4.0', # :source => "http://code.whytheluckystiff.net"
# File vendor/rails/railties/lib/initializer.rb, line 631 631: def gem(name, options = {}) 632: @gems << Rails::GemDependency.new(name, options) 633: end
# File vendor/rails/railties/lib/initializer.rb, line 579 579: def plugins=(plugins) 580: @plugins = plugins.nil? ? nil : plugins.map { |p| p.to_sym } 581: end
Returns true if plugin reloading is enabled.
# File vendor/rails/railties/lib/initializer.rb, line 612 612: def reload_plugins? 613: !!@reload_plugins 614: end
Set the root_path to RAILS_ROOT and canonicalize it.
# File vendor/rails/railties/lib/initializer.rb, line 679 679: def set_root_path! 680: raise 'RAILS_ROOT is not set' unless defined?(::RAILS_ROOT) 681: raise 'RAILS_ROOT is not a directory' unless File.directory?(::RAILS_ROOT) 682: 683: @root_path = 684: # Pathname is incompatible with Windows, but Windows doesn't have 685: # real symlinks so File.expand_path is safe. 686: if RUBY_PLATFORM =~ /(:?mswin|mingw)/ 687: File.expand_path(::RAILS_ROOT) 688: 689: # Otherwise use Pathname#realpath which respects symlinks. 690: else 691: Pathname.new(::RAILS_ROOT).realpath.to_s 692: end 693: 694: Object.const_set(:RELATIVE_RAILS_ROOT, ::RAILS_ROOT.dup) unless defined?(::RELATIVE_RAILS_ROOT) 695: ::RAILS_ROOT.replace @root_path 696: 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 733 733: def to_prepare(&callback) 734: after_initialize do 735: require 'dispatcher' unless defined?(::Dispatcher) 736: Dispatcher.to_prepare(&callback) 737: end 738: end