Class Rails::Configuration
In: 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)

Methods

Attributes

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
cache_classes  [RW]  Whether or not classes should be cached (set to false if you want application classes to be reloaded on each request)
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).
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.
root_path  [R]  The application’s base directory.
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.

Public Class methods

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

[Source]

# File railties/lib/initializer.rb, line 460
    def initialize
      set_root_path!

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

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

Public Instance methods

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.

[Source]

# File railties/lib/initializer.rb, line 525
    def after_initialize(&after_initialize_block)
      after_initialize_blocks << after_initialize_block if after_initialize_block
    end

Returns the blocks added with Configuration#after_initialize

[Source]

# File railties/lib/initializer.rb, line 530
    def after_initialize_blocks
      @after_initialize_blocks ||= []
    end

Deprecated options:

[Source]

# File railties/lib/initializer.rb, line 449
    def breakpoint_server(_ = nil)
      $stderr.puts %(
      *******************************************************************
      * config.breakpoint_server has been deprecated and has no effect. *
      *******************************************************************
      )
    end
breakpoint_server=(_ = nil)

Alias for breakpoint_server

[Source]

# File railties/lib/initializer.rb, line 543
    def builtin_directories
      # Include builtins only in the development environment.
      (environment == 'development') ? Dir["#{RAILTIES_PATH}/builtin/*/"] : []
    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.

[Source]

# File railties/lib/initializer.rb, line 506
    def database_configuration
      YAML::load(ERB.new(IO.read(database_configuration_file)).result)
    end

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

[Source]

# File railties/lib/initializer.rb, line 518
    def environment
      ::RAILS_ENV
    end

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

[Source]

# File railties/lib/initializer.rb, line 512
    def environment_path
      "#{root_path}/config/environments/#{environment}.rb"
    end

[Source]

# File railties/lib/initializer.rb, line 548
    def framework_paths
      # TODO: Don't include dirs for frameworks that are not used
      %w(
        railties
        railties/lib
        actionpack/lib
        activesupport/lib
        activerecord/lib
        activeresource/lib
        actionmailer/lib
      ).map { |dir| "#{framework_root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
    end

[Source]

# File railties/lib/initializer.rb, line 429
    def plugins=(plugins)
      @plugins = plugins.nil? ? nil : plugins.map { |p| p.to_sym }
    end

Set the root_path to RAILS_ROOT and canonicalize it.

[Source]

# File railties/lib/initializer.rb, line 484
    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.expand_path(::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

Add a preparation callback that will run before every request in development mode, or before the first request in production.

See Dispatcher#to_prepare.

[Source]

# File railties/lib/initializer.rb, line 538
    def to_prepare(&callback)
      require 'dispatcher' unless defined?(::Dispatcher)
      Dispatcher.to_prepare(&callback)
    end

Private Instance methods

[Source]

# File railties/lib/initializer.rb, line 626
      def default_cache_classes
        false
      end

[Source]

# File railties/lib/initializer.rb, line 616
      def default_controller_paths
        paths = [File.join(root_path, 'app', 'controllers')]
        paths.concat builtin_directories
        paths
      end

[Source]

# File railties/lib/initializer.rb, line 608
      def default_database_configuration_file
        File.join(root_path, 'config', 'database.yml')
      end

[Source]

# File railties/lib/initializer.rb, line 622
      def default_dependency_mechanism
        :load
      end

[Source]

# File railties/lib/initializer.rb, line 566
      def default_frameworks
        [ :active_record, :action_controller, :action_view, :action_mailer, :active_resource ]
      end

Doesn‘t matter since plugins aren’t in load_paths yet.

[Source]

# File railties/lib/initializer.rb, line 596
      def default_load_once_paths
        []
      end

[Source]

# File railties/lib/initializer.rb, line 570
      def default_load_paths
        paths = ["#{root_path}/test/mocks/#{environment}"]

        # Add the app's controller directory
        paths.concat(Dir["#{root_path}/app/controllers/"])

        # Then components subdirectories.
        paths.concat(Dir["#{root_path}/components/[_a-z]*"])

        # Followed by the standard includes.
        paths.concat %w(
          app
          app/models
          app/controllers
          app/helpers
          app/services
          components
          config
          lib
          vendor
        ).map { |dir| "#{root_path}/#{dir}" }.select { |dir| File.directory?(dir) }

        paths.concat builtin_directories
      end

[Source]

# File railties/lib/initializer.rb, line 604
      def default_log_level
        environment == 'production' ? :info : :debug
      end

[Source]

# File railties/lib/initializer.rb, line 600
      def default_log_path
        File.join(root_path, 'log', "#{environment}.log")
      end

[Source]

# File railties/lib/initializer.rb, line 646
      def default_plugin_loader
        Plugin::Loader
      end

[Source]

# File railties/lib/initializer.rb, line 642
      def default_plugin_locators
        [Plugin::FileSystemLocator]
      end

[Source]

# File railties/lib/initializer.rb, line 638
      def default_plugin_paths
        ["#{root_path}/vendor/plugins"]
      end

[Source]

# File railties/lib/initializer.rb, line 634
      def default_plugins
        nil
      end

[Source]

# File railties/lib/initializer.rb, line 612
      def default_view_path
        File.join(root_path, 'app', 'views')
      end

[Source]

# File railties/lib/initializer.rb, line 630
      def default_whiny_nils
        false
      end

[Source]

# File railties/lib/initializer.rb, line 562
      def framework_root_path
        defined?(::RAILS_FRAMEWORK_ROOT) ? ::RAILS_FRAMEWORK_ROOT : "#{root_path}/vendor/rails"
      end

[Validate]