Class: Rails::Configuration

Inherits:
Object show all
Defined in:
lib/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

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Create a new Configuration instance, initialized with the default values.



499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
# File 'lib/initializer.rb', line 499

def initialize
  self.frameworks                   = default_frameworks
  self.load_paths                   = default_load_paths
  self.load_once_paths              = default_load_once_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.plugins                      = default_plugins
  self.plugin_paths                 = default_plugin_paths
  self.database_configuration_file  = default_database_configuration_file

  for framework in default_frameworks
    self.send("#{framework}=", Rails::OrderedOptions.new)
  end
end

Instance Attribute Details

#action_controllerObject

A stub for setting options on ActionController::Base



418
419
420
# File 'lib/initializer.rb', line 418

def action_controller
  @action_controller
end

#action_mailerObject

A stub for setting options on ActionMailer::Base



421
422
423
# File 'lib/initializer.rb', line 421

def action_mailer
  @action_mailer
end

#action_viewObject

A stub for setting options on ActionView::Base



424
425
426
# File 'lib/initializer.rb', line 424

def action_view
  @action_view
end

#action_web_serviceObject

A stub for setting options on ActionWebService::Base



427
428
429
# File 'lib/initializer.rb', line 427

def action_web_service
  @action_web_service
end

#active_recordObject

A stub for setting options on ActiveRecord::Base



430
431
432
# File 'lib/initializer.rb', line 430

def active_record
  @active_record
end

#breakpoint_serverObject

Whether or not to use the breakpoint server (boolean)



433
434
435
# File 'lib/initializer.rb', line 433

def breakpoint_server
  @breakpoint_server
end

#cache_classesObject

Whether or not classes should be cached (set to false if you want application classes to be reloaded on each request)



437
438
439
# File 'lib/initializer.rb', line 437

def cache_classes
  @cache_classes
end

#connection_adaptersObject

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.)



442
443
444
# File 'lib/initializer.rb', line 442

def connection_adapters
  @connection_adapters
end

#controller_pathsObject

The list of paths that should be searched for controllers. (Defaults to app/controllers and components.)



446
447
448
# File 'lib/initializer.rb', line 446

def controller_paths
  @controller_paths
end

#database_configuration_fileObject

The path to the database configuration file to use. (Defaults to config/database.yml.)



450
451
452
# File 'lib/initializer.rb', line 450

def database_configuration_file
  @database_configuration_file
end

#frameworksObject

The list of rails framework components that should be loaded. (Defaults to :active_record, :action_controller, :action_view, :action_mailer, and :action_web_service).



456
457
458
# File 'lib/initializer.rb', line 456

def frameworks
  @frameworks
end

#load_once_pathsObject

An array of paths from which Rails will automatically load from only once. All elements of this array must also be in load_paths.



464
465
466
# File 'lib/initializer.rb', line 464

def load_once_paths
  @load_once_paths
end

#load_pathsObject

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.



460
461
462
# File 'lib/initializer.rb', line 460

def load_paths
  @load_paths
end

#log_levelObject

The log level to use for the default Rails logger. In production mode, this defaults to :info. In development mode, it defaults to :debug.



469
470
471
# File 'lib/initializer.rb', line 469

def log_level
  @log_level
end

#log_pathObject

The path to the log file to use. Defaults to log/##environment.log (e.g. log/development.log or log/production.log).



473
474
475
# File 'lib/initializer.rb', line 473

def log_path
  @log_path
end

#loggerObject

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.



479
480
481
# File 'lib/initializer.rb', line 479

def logger
  @logger
end

#plugin_pathsObject

The path to the root of the plugins directory. By default, it is in vendor/plugins.



495
496
497
# File 'lib/initializer.rb', line 495

def plugin_paths
  @plugin_paths
end

#pluginsObject

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.



491
492
493
# File 'lib/initializer.rb', line 491

def plugins
  @plugins
end

#view_pathObject

The root of the application’s views. (Defaults to app/views.)



482
483
484
# File 'lib/initializer.rb', line 482

def view_path
  @view_path
end

#whiny_nilsObject

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.



486
487
488
# File 'lib/initializer.rb', line 486

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.



541
542
543
# File 'lib/initializer.rb', line 541

def after_initialize(&after_initialize_block)
  @after_initialize_block = after_initialize_block
end

#after_initialize_blockObject

Returns the block set in Configuration#after_initialize



546
547
548
# File 'lib/initializer.rb', line 546

def after_initialize_block
  @after_initialize_block
end

#builtin_directoriesObject



559
560
561
562
# File 'lib/initializer.rb', line 559

def builtin_directories
  # Include builtins only in the development environment.
  (environment == 'development') ? Dir["#{RAILTIES_PATH}/builtin/*/"] : []
end

#database_configurationObject

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.



522
523
524
# File 'lib/initializer.rb', line 522

def database_configuration
  YAML::load(ERB.new(IO.read(database_configuration_file)).result)
end

#environmentObject

Return the currently selected environment. By default, it returns the value of the RAILS_ENV constant.



534
535
536
# File 'lib/initializer.rb', line 534

def environment
  ::RAILS_ENV
end

#environment_pathObject

The path to the current environment’s file (development.rb, etc.). By default the file is at config/environments/#{environment}.rb.



528
529
530
# File 'lib/initializer.rb', line 528

def environment_path
  "#{root_path}/config/environments/#{environment}.rb"
end

#framework_pathsObject



564
565
566
567
568
569
570
571
572
573
574
575
# File 'lib/initializer.rb', line 564

def framework_paths
  # TODO: Don't include dirs for frameworks that are not used
  %w(
    railties
    railties/lib
    actionpack/lib
    activesupport/lib
    activerecord/lib
    actionmailer/lib
    actionwebservice/lib
  ).map { |dir| "#{framework_root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
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.



554
555
556
557
# File 'lib/initializer.rb', line 554

def to_prepare(&callback)
  require 'dispatcher' unless defined?(::Dispatcher)
  Dispatcher.to_prepare(&callback)
end