Class: Rails::Configuration
- Inherits:
-
Object
- Object
- Rails::Configuration
- Defined in:
- lib/rails-2.3.14/initializer.rb
Overview
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)
Instance Attribute Summary collapse
-
#action_controller ⇒ Object
A stub for setting options on ActionController::Base.
-
#action_mailer ⇒ Object
A stub for setting options on ActionMailer::Base.
-
#action_view ⇒ Object
A stub for setting options on ActionView::Base.
-
#active_record ⇒ Object
A stub for setting options on ActiveRecord::Base.
-
#active_resource ⇒ Object
A stub for setting options on ActiveResource::Base.
-
#active_support ⇒ Object
A stub for setting options on ActiveSupport.
-
#autoload_once_paths ⇒ Object
An array of paths from which Rails will automatically load from only once.
-
#autoload_paths ⇒ Object
An array of additional paths to prepend to the load path.
-
#cache_classes ⇒ Object
Whether or not classes should be cached (set to false if you want application classes to be reloaded on each request).
-
#cache_store ⇒ Object
The specific cache store to use.
-
#controller_paths ⇒ Object
The list of paths that should be searched for controllers.
-
#database_configuration_file ⇒ Object
The path to the database configuration file to use.
-
#dependency_loading ⇒ Object
Enables or disables dependency loading during the request cycle.
-
#eager_load_paths ⇒ Object
An array of paths from which Rails will eager load on boot if cache classes is enabled.
-
#frameworks ⇒ Object
The list of rails framework components that should be loaded.
-
#gems ⇒ Object
An array of gems that this rails application depends on.
-
#i18n ⇒ Object
Accessor for i18n settings.
-
#log_level ⇒ Object
The log level to use for the default Rails logger.
-
#log_path ⇒ Object
The path to the log file to use.
-
#logger ⇒ Object
The specific logger to use.
-
#metals ⇒ Object
The list of metals to load.
-
#plugin_loader ⇒ Object
The class that handles loading each plugin.
-
#plugin_locators ⇒ Object
The classes that handle finding the desired plugins that you’d like to load for your application.
-
#plugin_paths ⇒ Object
The path to the root of the plugins directory.
-
#plugins ⇒ Object
The list of plugins to load.
-
#preload_frameworks ⇒ Object
Whether to preload all frameworks at startup.
-
#reload_plugins ⇒ Object
Enables or disables plugin reloading.
-
#root_path ⇒ Object
readonly
The application’s base directory.
-
#routes_configuration_file ⇒ Object
The path to the routes configuration file to use.
-
#time_zone ⇒ Object
Sets the default
time_zone
. -
#view_path ⇒ Object
The root of the application’s views.
-
#whiny_nils ⇒ Object
Set to
true
if you want to be warned (noisily) when you try to invoke any method ofnil
.
Instance Method Summary collapse
-
#after_initialize(&after_initialize_block) ⇒ Object
Adds a block which will be executed after rails has been fully initialized.
-
#after_initialize_blocks ⇒ Object
Returns the blocks added with Configuration#after_initialize.
-
#breakpoint_server(_ = nil) ⇒ Object
(also: #breakpoint_server=)
Deprecated options:.
- #builtin_directories ⇒ Object
-
#database_configuration ⇒ Object
Loads and returns the contents of the #database_configuration_file.
-
#environment ⇒ Object
Return the currently selected environment.
-
#environment_path ⇒ Object
The path to the current environment’s file (
development.rb
, etc.). - #framework_paths ⇒ Object
-
#gem(name, options = {}) ⇒ Object
Adds a single Gem dependency to the rails application.
-
#initialize ⇒ Configuration
constructor
Create a new Configuration instance, initialized with the default values.
-
#load_once_paths ⇒ Object
Deprecated, use autoload_once_paths.
-
#load_once_paths=(paths) ⇒ Object
Deprecated, use autoload_once_paths=.
-
#load_paths ⇒ Object
Deprecated, use autoload_paths.
-
#load_paths=(paths) ⇒ Object
Deprecated, use autoload_paths=.
- #middleware ⇒ Object
-
#reload_plugins? ⇒ Boolean
Returns true if plugin reloading is enabled.
-
#set_root_path! ⇒ Object
Set the root_path to RAILS_ROOT and canonicalize it.
-
#threadsafe! ⇒ Object
Enable threaded mode.
-
#to_prepare(&callback) ⇒ Object
Add a preparation callback that will run before every request in development mode, or before the first request in production.
Constructor Details
#initialize ⇒ Configuration
Create a new Configuration instance, initialized with the default values.
885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 |
# File 'lib/rails-2.3.14/initializer.rb', line 885 def initialize set_root_path! self.frameworks = default_frameworks self.autoload_paths = default_autoload_paths self.autoload_once_paths = default_autoload_once_paths self.eager_load_paths = default_eager_load_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.preload_frameworks = default_preload_frameworks self.cache_classes = default_cache_classes self.dependency_loading = default_dependency_loading self.whiny_nils = default_whiny_nils self.plugins = default_plugins self.plugin_paths = default_plugin_paths self.plugin_locators = default_plugin_locators self.plugin_loader = default_plugin_loader self.database_configuration_file = default_database_configuration_file self.routes_configuration_file = default_routes_configuration_file self.gems = default_gems self.i18n = default_i18n for framework in default_frameworks self.send("#{framework}=", Rails::OrderedOptions.new) end self.active_support = Rails::OrderedOptions.new end |
Instance Attribute Details
#action_controller ⇒ Object
A stub for setting options on ActionController::Base.
681 682 683 |
# File 'lib/rails-2.3.14/initializer.rb', line 681 def action_controller @action_controller end |
#action_mailer ⇒ Object
A stub for setting options on ActionMailer::Base.
684 685 686 |
# File 'lib/rails-2.3.14/initializer.rb', line 684 def action_mailer @action_mailer end |
#action_view ⇒ Object
A stub for setting options on ActionView::Base.
687 688 689 |
# File 'lib/rails-2.3.14/initializer.rb', line 687 def action_view @action_view end |
#active_record ⇒ Object
A stub for setting options on ActiveRecord::Base.
690 691 692 |
# File 'lib/rails-2.3.14/initializer.rb', line 690 def active_record @active_record end |
#active_resource ⇒ Object
A stub for setting options on ActiveResource::Base.
693 694 695 |
# File 'lib/rails-2.3.14/initializer.rb', line 693 def active_resource @active_resource end |
#active_support ⇒ Object
A stub for setting options on ActiveSupport.
696 697 698 |
# File 'lib/rails-2.3.14/initializer.rb', line 696 def active_support @active_support end |
#autoload_once_paths ⇒ Object
An array of paths from which Rails will automatically load from only once. All elements of this array must also be in autoload_paths
.
741 742 743 |
# File 'lib/rails-2.3.14/initializer.rb', line 741 def autoload_once_paths @autoload_once_paths end |
#autoload_paths ⇒ Object
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.
725 726 727 |
# File 'lib/rails-2.3.14/initializer.rb', line 725 def autoload_paths @autoload_paths end |
#cache_classes ⇒ Object
Whether or not classes should be cached (set to false if you want application classes to be reloaded on each request)
703 704 705 |
# File 'lib/rails-2.3.14/initializer.rb', line 703 def cache_classes @cache_classes end |
#cache_store ⇒ Object
The specific cache store to use. By default, the ActiveSupport::Cache::Store will be used.
776 777 778 |
# File 'lib/rails-2.3.14/initializer.rb', line 776 def cache_store @cache_store end |
#controller_paths ⇒ Object
The list of paths that should be searched for controllers. (Defaults to app/controllers
.)
707 708 709 |
# File 'lib/rails-2.3.14/initializer.rb', line 707 def controller_paths @controller_paths end |
#database_configuration_file ⇒ Object
The path to the database configuration file to use. (Defaults to config/database.yml
.)
711 712 713 |
# File 'lib/rails-2.3.14/initializer.rb', line 711 def database_configuration_file @database_configuration_file end |
#dependency_loading ⇒ Object
Enables or disables dependency loading during the request cycle. Setting dependency_loading
to true will allow new classes to be loaded during a request. Setting it to false will disable this behavior.
Those who want to run in a threaded environment should disable this option and eager load or require all there classes on initialization.
If cache_classes
is disabled, dependency loaded will always be on.
840 841 842 |
# File 'lib/rails-2.3.14/initializer.rb', line 840 def dependency_loading @dependency_loading end |
#eager_load_paths ⇒ Object
An array of paths from which Rails will eager load on boot if cache classes is enabled. All elements of this array must also be in autoload_paths
.
758 759 760 |
# File 'lib/rails-2.3.14/initializer.rb', line 758 def eager_load_paths @eager_load_paths end |
#frameworks ⇒ Object
The list of rails framework components that should be loaded. (Defaults to :active_record
, :action_controller
, :action_view
, :action_mailer
, and :active_resource
).
721 722 723 |
# File 'lib/rails-2.3.14/initializer.rb', line 721 def frameworks @frameworks end |
#gems ⇒ Object
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.
848 849 850 |
# File 'lib/rails-2.3.14/initializer.rb', line 848 def gems @gems end |
#i18n ⇒ Object
Accessor for i18n settings.
881 882 883 |
# File 'lib/rails-2.3.14/initializer.rb', line 881 def i18n @i18n end |
#log_level ⇒ Object
The log level to use for the default Rails logger. In production mode, this defaults to :info
. In development mode, it defaults to :debug
.
763 764 765 |
# File 'lib/rails-2.3.14/initializer.rb', line 763 def log_level @log_level end |
#log_path ⇒ Object
The path to the log file to use. Defaults to log/##environment.log (e.g. log/development.log or log/production.log).
767 768 769 |
# File 'lib/rails-2.3.14/initializer.rb', line 767 def log_path @log_path end |
#logger ⇒ Object
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.
773 774 775 |
# File 'lib/rails-2.3.14/initializer.rb', line 773 def logger @logger end |
#metals ⇒ Object
The list of metals to load. If this is set to nil
, all metals will be loaded in alphabetical order. If this is set to []
, no metals will be loaded. Otherwise metals will be loaded in the order specified
796 797 798 |
# File 'lib/rails-2.3.14/initializer.rb', line 796 def @metals end |
#plugin_loader ⇒ Object
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.
811 812 813 |
# File 'lib/rails-2.3.14/initializer.rb', line 811 def plugin_loader @plugin_loader end |
#plugin_locators ⇒ Object
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
.
806 807 808 |
# File 'lib/rails-2.3.14/initializer.rb', line 806 def plugin_locators @plugin_locators end |
#plugin_paths ⇒ Object
The path to the root of the plugins directory. By default, it is in vendor/plugins
.
800 801 802 |
# File 'lib/rails-2.3.14/initializer.rb', line 800 def plugin_paths @plugin_paths end |
#plugins ⇒ Object
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.
788 789 790 |
# File 'lib/rails-2.3.14/initializer.rb', line 788 def plugins @plugins end |
#preload_frameworks ⇒ Object
Whether to preload all frameworks at startup.
699 700 701 |
# File 'lib/rails-2.3.14/initializer.rb', line 699 def preload_frameworks @preload_frameworks end |
#reload_plugins ⇒ Object
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.autoload_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.autoload_once_paths << lib_path
824 825 826 |
# File 'lib/rails-2.3.14/initializer.rb', line 824 def reload_plugins @reload_plugins end |
#root_path ⇒ Object (readonly)
The application’s base directory.
678 679 680 |
# File 'lib/rails-2.3.14/initializer.rb', line 678 def root_path @root_path end |
#routes_configuration_file ⇒ Object
The path to the routes configuration file to use. (Defaults to config/routes.rb
.)
715 716 717 |
# File 'lib/rails-2.3.14/initializer.rb', line 715 def routes_configuration_file @routes_configuration_file end |
#time_zone ⇒ Object
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
.
878 879 880 |
# File 'lib/rails-2.3.14/initializer.rb', line 878 def time_zone @time_zone end |
#view_path ⇒ Object
The root of the application’s views. (Defaults to app/views
.)
779 780 781 |
# File 'lib/rails-2.3.14/initializer.rb', line 779 def view_path @view_path end |
#whiny_nils ⇒ Object
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.
783 784 785 |
# File 'lib/rails-2.3.14/initializer.rb', line 783 def whiny_nils @whiny_nils end |
Instance Method Details
#after_initialize(&after_initialize_block) ⇒ Object
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.
970 971 972 |
# File 'lib/rails-2.3.14/initializer.rb', line 970 def after_initialize(&after_initialize_block) after_initialize_blocks << after_initialize_block if after_initialize_block end |
#after_initialize_blocks ⇒ Object
Returns the blocks added with Configuration#after_initialize
975 976 977 |
# File 'lib/rails-2.3.14/initializer.rb', line 975 def after_initialize_blocks @after_initialize_blocks ||= [] end |
#breakpoint_server(_ = nil) ⇒ Object Also known as: breakpoint_server=
Deprecated options:
866 867 868 869 870 871 872 |
# File 'lib/rails-2.3.14/initializer.rb', line 866 def breakpoint_server(_ = nil) $stderr.puts %( ******************************************************************* * config.breakpoint_server has been deprecated and has no effect. * ******************************************************************* ) end |
#builtin_directories ⇒ Object
995 996 997 998 |
# File 'lib/rails-2.3.14/initializer.rb', line 995 def builtin_directories # Include builtins only in the development environment. (environment == 'development') ? Dir["#{RAILTIES_PATH}/builtin/*/"] : [] end |
#database_configuration ⇒ Object
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.
950 951 952 953 |
# File 'lib/rails-2.3.14/initializer.rb', line 950 def database_configuration require 'erb' YAML::load(ERB.new(IO.read(database_configuration_file)).result) end |
#environment ⇒ Object
Return the currently selected environment. By default, it returns the value of the RAILS_ENV constant.
963 964 965 |
# File 'lib/rails-2.3.14/initializer.rb', line 963 def environment ::RAILS_ENV end |
#environment_path ⇒ Object
The path to the current environment’s file (development.rb
, etc.). By default the file is at config/environments/#{environment}.rb
.
957 958 959 |
# File 'lib/rails-2.3.14/initializer.rb', line 957 def environment_path "#{root_path}/config/environments/#{environment}.rb" end |
#framework_paths ⇒ Object
1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 |
# File 'lib/rails-2.3.14/initializer.rb', line 1000 def framework_paths paths = %w(railties railties/lib activesupport/lib) paths << 'actionpack/lib' if frameworks.include?(:action_controller) || frameworks.include?(:action_view) [:active_record, :action_mailer, :active_resource, :action_web_service].each do |framework| paths << "#{framework.to_s.gsub('_', '')}/lib" if frameworks.include?(framework) end paths.map { |dir| "#{framework_root_path}/#{dir}" }.select { |dir| File.directory?(dir) } end |
#gem(name, options = {}) ⇒ Object
Adds a single Gem dependency to the rails application. By default, it will require the library with the same name as the gem. Use :lib to specify a different name.
# 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"
To require a library be installed, but not attempt to load it, pass :lib => false
config.gem 'qrp', :version => '0.4.1', :lib => false
861 862 863 |
# File 'lib/rails-2.3.14/initializer.rb', line 861 def gem(name, = {}) @gems << Rails::GemDependency.new(name, ) end |
#load_once_paths ⇒ Object
Deprecated, use autoload_once_paths.
744 745 746 747 |
# File 'lib/rails-2.3.14/initializer.rb', line 744 def load_once_paths $stderr.puts("config.load_once_paths is deprecated and removed in Rails 3, please use autoload_once_paths instead") autoload_once_paths end |
#load_once_paths=(paths) ⇒ Object
Deprecated, use autoload_once_paths=.
750 751 752 753 |
# File 'lib/rails-2.3.14/initializer.rb', line 750 def load_once_paths=(paths) $stderr.puts("config.load_once_paths= is deprecated and removed in Rails 3, please use autoload_once_paths= instead") self.autoload_once_paths = paths end |
#load_paths ⇒ Object
Deprecated, use autoload_paths.
728 729 730 731 |
# File 'lib/rails-2.3.14/initializer.rb', line 728 def load_paths $stderr.puts("config.load_paths is deprecated and removed in Rails 3, please use autoload_paths instead") autoload_paths end |
#load_paths=(paths) ⇒ Object
Deprecated, use autoload_paths=.
734 735 736 737 |
# File 'lib/rails-2.3.14/initializer.rb', line 734 def load_paths=(paths) $stderr.puts("config.load_paths= is deprecated and removed in Rails 3, please use autoload_paths= instead") self.autoload_paths = paths end |
#middleware ⇒ Object
990 991 992 993 |
# File 'lib/rails-2.3.14/initializer.rb', line 990 def middleware require 'action_controller' ActionController::Dispatcher.middleware end |
#reload_plugins? ⇒ Boolean
Returns true if plugin reloading is enabled.
827 828 829 |
# File 'lib/rails-2.3.14/initializer.rb', line 827 def reload_plugins? !!@reload_plugins end |
#set_root_path! ⇒ Object
Set the root_path to RAILS_ROOT and canonicalize it.
916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 |
# File 'lib/rails-2.3.14/initializer.rb', line 916 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 =~ /(:?mswin|mingw)/ File.(::RAILS_ROOT) # Otherwise use Pathname#realpath which respects symlinks. else Pathname.new(::RAILS_ROOT).realpath.to_s end Object.const_set(:RELATIVE_RAILS_ROOT, ::RAILS_ROOT.dup) unless defined?(::RELATIVE_RAILS_ROOT) ::RAILS_ROOT.replace @root_path end |
#threadsafe! ⇒ Object
Enable threaded mode. Allows concurrent requests to controller actions and multiple database connections. Also disables automatic dependency loading after boot, and disables reloading code on every request, as these are fundamentally incompatible with thread safety.
939 940 941 942 943 944 945 |
# File 'lib/rails-2.3.14/initializer.rb', line 939 def threadsafe! self.preload_frameworks = true self.cache_classes = true self.dependency_loading = false self.action_controller.allow_concurrency = true self end |
#to_prepare(&callback) ⇒ Object
Add a preparation callback that will run before every request in development mode, or before the first request in production.
See Dispatcher#to_prepare.
983 984 985 986 987 988 |
# File 'lib/rails-2.3.14/initializer.rb', line 983 def to_prepare(&callback) after_initialize do require 'dispatcher' unless defined?(::Dispatcher) Dispatcher.to_prepare(&callback) end end |