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)
- after_initialize
- after_initialize_blocks
- breakpoint_server
- breakpoint_server=
- builtin_directories
- database_configuration
- environment
- environment_path
- framework_paths
- gem
- new
- plugins=
- reload_plugins?
- set_root_path!
- to_prepare
| [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] | active_record | A stub for setting options on ActiveRecord::Base. |
| [RW] | active_resource | A stub for setting options on ActiveRecord::Base. |
| [RW] | active_support | A stub for setting options on ActiveSupport. |
| [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] | cache_store | The specific cache store to use. By default, the ActiveSupport::Cache::Store will be used. |
| [RW] | controller_paths | The list of paths that should be searched for controllers. (Defaults to app/controllers and components.) |
| [RW] | database_configuration_file | The path to the database configuration file to use. (Defaults to config/database.yml.) |
| [RW] | frameworks | The list of rails framework components that should be loaded. (Defaults to :active_record, :action_controller, :action_view, :action_mailer, and :active_resource). |
| [RW] | gems |
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. |
| [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 load_paths. |
| [RW] | load_paths | 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. |
| [RW] | log_level | The log level to use for the default Rails logger. In production mode, this defaults to :info. In development mode, it defaults to :debug. |
| [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_loader | 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. |
| [RW] | plugin_locators | 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. |
| [RW] | plugin_paths | The path to the root of the plugins directory. By default, it is in vendor/plugins. |
| [R] | plugins | 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. |
| [RW] | reload_plugins |
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:
ActiveSupport::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: ActiveSupport::Dependencies.load_once_paths << lib_path |
| [R] | root_path | The application‘s base directory. |
| [RW] | routes_configuration_file | The path to the routes configuration file to use. (Defaults to config/routes.rb.) |
| [RW] | time_zone | 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. |
| [RW] | view_path | The root of the application‘s views. (Defaults to app/views.) |
| [RW] | whiny_nils | 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.
[ show source ]
# File railties/lib/initializer.rb, line 655
655: def initialize
656: set_root_path!
657:
658: self.frameworks = default_frameworks
659: self.load_paths = default_load_paths
660: self.load_once_paths = default_load_once_paths
661: self.log_path = default_log_path
662: self.log_level = default_log_level
663: self.view_path = default_view_path
664: self.controller_paths = default_controller_paths
665: self.cache_classes = default_cache_classes
666: self.whiny_nils = default_whiny_nils
667: self.plugins = default_plugins
668: self.plugin_paths = default_plugin_paths
669: self.plugin_locators = default_plugin_locators
670: self.plugin_loader = default_plugin_loader
671: self.database_configuration_file = default_database_configuration_file
672: self.routes_configuration_file = default_routes_configuration_file
673: self.gems = default_gems
674:
675: for framework in default_frameworks
676: self.send("#{framework}=", Rails::OrderedOptions.new)
677: end
678: self.active_support = Rails::OrderedOptions.new
679: 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.
[ show source ]
# File railties/lib/initializer.rb, line 723
723: def after_initialize(&after_initialize_block)
724: after_initialize_blocks << after_initialize_block if after_initialize_block
725: end
Returns the blocks added with Configuration#after_initialize
[ show source ]
# File railties/lib/initializer.rb, line 728
728: def after_initialize_blocks
729: @after_initialize_blocks ||= []
730: end
Deprecated options:
[ show source ]
# File railties/lib/initializer.rb, line 639
639: def breakpoint_server(_ = nil)
640: $stderr.puts %(
641: *******************************************************************
642: * config.breakpoint_server has been deprecated and has no effect. *
643: *******************************************************************
644: )
645: end
Alias for breakpoint_server
[ show source ]
# File railties/lib/initializer.rb, line 743
743: def builtin_directories
744: # Include builtins only in the development environment.
745: (environment == 'development') ? Dir["#{RAILTIES_PATH}/builtin/*/"] : []
746: 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.
[ show source ]
# File railties/lib/initializer.rb, line 704
704: def database_configuration
705: YAML::load(ERB.new(IO.read(database_configuration_file)).result)
706: end
Return the currently selected environment. By default, it returns the value of the RAILS_ENV constant.
[ show source ]
# File railties/lib/initializer.rb, line 716
716: def environment
717: ::RAILS_ENV
718: end
The path to the current environment‘s file (development.rb, etc.). By default the file is at config/environments/#{environment}.rb.
[ show source ]
# File railties/lib/initializer.rb, line 710
710: def environment_path
711: "#{root_path}/config/environments/#{environment}.rb"
712: end
[ show source ]
# File railties/lib/initializer.rb, line 748
748: def framework_paths
749: paths = %w(railties railties/lib activesupport/lib)
750: paths << 'actionpack/lib' if frameworks.include? :action_controller or frameworks.include? :action_view
751:
752: [:active_record, :action_mailer, :active_resource, :action_web_service].each do |framework|
753: paths << "#{framework.to_s.gsub('_', '')}/lib" if frameworks.include? framework
754: end
755:
756: paths.map { |dir| "#{framework_root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
757: 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"
[ show source ]
# File railties/lib/initializer.rb, line 634
634: def gem(name, options = {})
635: @gems << Rails::GemDependency.new(name, options)
636: end
[ show source ]
# File railties/lib/initializer.rb, line 582
582: def plugins=(plugins)
583: @plugins = plugins.nil? ? nil : plugins.map { |p| p.to_sym }
584: end
Returns true if plugin reloading is enabled.
[ show source ]
# File railties/lib/initializer.rb, line 615
615: def reload_plugins?
616: !!@reload_plugins
617: end
Set the root_path to RAILS_ROOT and canonicalize it.
[ show source ]
# File railties/lib/initializer.rb, line 682
682: def set_root_path!
683: raise 'RAILS_ROOT is not set' unless defined?(::RAILS_ROOT)
684: raise 'RAILS_ROOT is not a directory' unless File.directory?(::RAILS_ROOT)
685:
686: @root_path =
687: # Pathname is incompatible with Windows, but Windows doesn't have
688: # real symlinks so File.expand_path is safe.
689: if RUBY_PLATFORM =~ /(:?mswin|mingw)/
690: File.expand_path(::RAILS_ROOT)
691:
692: # Otherwise use Pathname#realpath which respects symlinks.
693: else
694: Pathname.new(::RAILS_ROOT).realpath.to_s
695: end
696:
697: Object.const_set(:RELATIVE_RAILS_ROOT, ::RAILS_ROOT.dup) unless defined?(::RELATIVE_RAILS_ROOT)
698: ::RAILS_ROOT.replace @root_path
699: 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.
[ show source ]
# File railties/lib/initializer.rb, line 736
736: def to_prepare(&callback)
737: after_initialize do
738: require 'dispatcher' unless defined?(::Dispatcher)
739: Dispatcher.to_prepare(&callback)
740: end
741: end