aboutsummaryrefslogblamecommitdiffstats
path: root/activesupport/lib/active_support/railtie.rb
blob: f696716cc8ec24a99893d3b42a89082b7c5e4c56 (plain) (tree)
1
2
3
4
5
6
7
                        
                                     
 

                                
                                                             
 












                                                                            

                                                                               





                                                                            

                                                                              






                                                       

                                                                                     
                                                              
                                                  
                                                          









                                                                                           
   
require "active_support"
require "active_support/i18n_railtie"

module ActiveSupport
  class Railtie < Rails::Railtie
    config.active_support = ActiveSupport::OrderedOptions.new

    initializer "active_support.deprecation_behavior" do |app|
      if deprecation = app.config.active_support.deprecation
        ActiveSupport::Deprecation.behavior = deprecation
      else
        defaults = {"development" => :log,
                    "production"  => :notify,
                    "test"        => :stderr}

        env = Rails.env

        if defaults.key?(env)
          msg = "You did not specify how you would like Rails to report " \
                "deprecation notices for your #{env} environment, please " \
                "set config.active_support.deprecation to :#{defaults[env]} " \
                "at config/environments/#{env}.rb"

          warn msg
          ActiveSupport::Deprecation.behavior = defaults[env]
        else
          msg = "You did not specify how you would like Rails to report " \
                "deprecation notices for your #{env} environment, please " \
                "set config.active_support.deprecation to :log, :notify or " \
                ":stderr at config/environments/#{env}.rb"

          warn msg
          ActiveSupport::Deprecation.behavior = :stderr
        end
      end
    end

    # Sets the default value for Time.zone
    # If assigned value cannot be matched to a TimeZone, an exception will be raised.
    initializer "active_support.initialize_time_zone" do |app|
      require 'active_support/core_ext/time/zones'
      zone_default = Time.find_zone!(app.config.time_zone)

      unless zone_default
        raise \
          'Value assigned to config.time_zone not recognized.' +
          'Run "rake -D time" for a list of tasks for finding appropriate time zone names.'
      end

      Time.zone_default = zone_default
    end
  end
end