Class: Rails::Configuration
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.
-
#action_web_service ⇒ Object
A stub for setting options on ActionWebService::Base.
-
#active_record ⇒ Object
A stub for setting options on ActiveRecord::Base.
-
#breakpoint_server ⇒ Object
Whether or not to use the breakpoint server (boolean).
-
#cache_classes ⇒ Object
Whether or not classes should be cached (set to false if you want application classes to be reloaded on each request).
-
#connection_adapters ⇒ Object
The list of connection adapters to load.
-
#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.
-
#frameworks ⇒ Object
The list of rails framework components that should be loaded.
-
#load_paths ⇒ Object
An array of additional paths to prepend to the load path.
-
#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.
-
#plugin_paths ⇒ Object
The path to the root of the plugins directory.
-
#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
Sets a block which will be executed after rails has been fully initialized.
-
#after_initialize_block ⇒ Object
Returns the block set in Configuration#after_initialize.
-
#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.).
-
#initialize ⇒ Configuration
constructor
Create a new Configuration instance, initialized with the default values.
Constructor Details
#initialize ⇒ Configuration
Create a new Configuration instance, initialized with the default values.
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 |
# File 'lib/initializer.rb', line 437 def initialize self.frameworks = default_frameworks self.load_paths = default_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.cache_classes = default_cache_classes self.breakpoint_server = default_breakpoint_server self.whiny_nils = default_whiny_nils self.plugin_paths = default_plugin_paths self.database_configuration_file = default_database_configuration_file for framework in default_frameworks self.send("#{framework}=", OrderedOptions.new) end end |
Instance Attribute Details
#action_controller ⇒ Object
A stub for setting options on ActionController::Base
365 366 367 |
# File 'lib/initializer.rb', line 365 def action_controller @action_controller end |
#action_mailer ⇒ Object
A stub for setting options on ActionMailer::Base
368 369 370 |
# File 'lib/initializer.rb', line 368 def action_mailer @action_mailer end |
#action_view ⇒ Object
A stub for setting options on ActionView::Base
371 372 373 |
# File 'lib/initializer.rb', line 371 def action_view @action_view end |
#action_web_service ⇒ Object
A stub for setting options on ActionWebService::Base
374 375 376 |
# File 'lib/initializer.rb', line 374 def action_web_service @action_web_service end |
#active_record ⇒ Object
A stub for setting options on ActiveRecord::Base
377 378 379 |
# File 'lib/initializer.rb', line 377 def active_record @active_record end |
#breakpoint_server ⇒ Object
Whether or not to use the breakpoint server (boolean)
380 381 382 |
# File 'lib/initializer.rb', line 380 def breakpoint_server @breakpoint_server 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)
384 385 386 |
# File 'lib/initializer.rb', line 384 def cache_classes @cache_classes end |
#connection_adapters ⇒ Object
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.)
389 390 391 |
# File 'lib/initializer.rb', line 389 def connection_adapters @connection_adapters end |
#controller_paths ⇒ Object
The list of paths that should be searched for controllers. (Defaults to app/controllers
and components
.)
393 394 395 |
# File 'lib/initializer.rb', line 393 def controller_paths @controller_paths end |
#database_configuration_file ⇒ Object
The path to the database configuration file to use. (Defaults to config/database.yml
.)
397 398 399 |
# File 'lib/initializer.rb', line 397 def database_configuration_file @database_configuration_file end |
#frameworks ⇒ Object
The list of rails framework components that should be loaded. (Defaults to :active_record
, :action_controller
, :action_view
, :action_mailer
, and :action_web_service
).
403 404 405 |
# File 'lib/initializer.rb', line 403 def frameworks @frameworks end |
#load_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.
407 408 409 |
# File 'lib/initializer.rb', line 407 def load_paths @load_paths 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
.
412 413 414 |
# File 'lib/initializer.rb', line 412 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).
416 417 418 |
# File 'lib/initializer.rb', line 416 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.
422 423 424 |
# File 'lib/initializer.rb', line 422 def logger @logger end |
#plugin_paths ⇒ Object
The path to the root of the plugins directory. By default, it is in vendor/plugins
.
433 434 435 |
# File 'lib/initializer.rb', line 433 def plugin_paths @plugin_paths end |
#view_path ⇒ Object
The root of the application’s views. (Defaults to app/views
.)
425 426 427 |
# File 'lib/initializer.rb', line 425 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.
429 430 431 |
# File 'lib/initializer.rb', line 429 def whiny_nils @whiny_nils end |
Instance Method Details
#after_initialize(&after_initialize_block) ⇒ Object
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.
477 478 479 |
# File 'lib/initializer.rb', line 477 def after_initialize(&after_initialize_block) @after_initialize_block = after_initialize_block end |
#after_initialize_block ⇒ Object
Returns the block set in Configuration#after_initialize
482 483 484 |
# File 'lib/initializer.rb', line 482 def after_initialize_block @after_initialize_block 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.
458 459 460 |
# File 'lib/initializer.rb', line 458 def database_configuration 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.
470 471 472 |
# File 'lib/initializer.rb', line 470 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
.
464 465 466 |
# File 'lib/initializer.rb', line 464 def environment_path "#{root_path}/config/environments/#{environment}.rb" end |