2010-03-02 15:32:31 -05:00
|
|
|
require "active_support/notifications"
|
2011-05-07 07:35:04 -04:00
|
|
|
require "active_support/dependencies"
|
2010-06-19 11:51:29 -04:00
|
|
|
require "active_support/descendants_tracker"
|
2010-03-02 15:32:31 -05:00
|
|
|
|
2010-01-23 10:07:20 -05:00
|
|
|
module Rails
|
|
|
|
class Application
|
|
|
|
module Bootstrap
|
|
|
|
include Initializable
|
|
|
|
|
2012-10-14 06:03:39 -04:00
|
|
|
initializer :load_environment_hook, group: :all do end
|
2010-01-24 06:15:46 -05:00
|
|
|
|
2012-10-14 06:03:39 -04:00
|
|
|
initializer :load_active_support, group: :all do
|
2012-05-12 11:54:28 -04:00
|
|
|
require "active_support/all" unless config.active_support.bare
|
2010-01-23 10:07:20 -05:00
|
|
|
end
|
|
|
|
|
2012-10-14 06:03:39 -04:00
|
|
|
initializer :set_eager_load, group: :all do
|
2012-08-01 09:07:01 -04:00
|
|
|
if config.eager_load.nil?
|
|
|
|
warn <<-INFO
|
2012-08-01 14:54:22 -04:00
|
|
|
config.eager_load is set to nil. Please update your config/environments/*.rb files accordingly:
|
2012-08-01 09:07:01 -04:00
|
|
|
|
|
|
|
* development - set it to false
|
|
|
|
* test - set it to false (unless you use a tool that preloads your test environment)
|
|
|
|
* production - set it to true
|
|
|
|
|
|
|
|
INFO
|
|
|
|
config.eager_load = config.cache_classes
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-01-23 10:07:20 -05:00
|
|
|
# Initialize the logger early in the stack in case we need to log some deprecation.
|
2012-10-14 06:03:39 -04:00
|
|
|
initializer :initialize_logger, group: :all do
|
2010-01-25 18:08:08 -05:00
|
|
|
Rails.logger ||= config.logger || begin
|
2010-10-06 11:18:59 -04:00
|
|
|
path = config.paths["log"].first
|
2011-12-09 19:03:18 -05:00
|
|
|
unless File.exist? File.dirname path
|
|
|
|
FileUtils.mkdir_p File.dirname path
|
|
|
|
end
|
|
|
|
|
2012-01-03 12:13:24 -05:00
|
|
|
f = File.open path, 'a'
|
2011-12-09 19:03:18 -05:00
|
|
|
f.binmode
|
2012-02-10 15:59:58 -05:00
|
|
|
f.sync = config.autoflush_log # if true make sure every write flushes
|
2011-12-09 19:03:18 -05:00
|
|
|
|
2013-03-15 13:38:00 -04:00
|
|
|
logger = ActiveSupport::Logger.new f
|
|
|
|
logger.formatter = config.log_formatter
|
|
|
|
logger = ActiveSupport::TaggedLogging.new(logger)
|
|
|
|
logger
|
2011-08-24 16:25:11 -04:00
|
|
|
rescue StandardError
|
2011-12-19 21:41:37 -05:00
|
|
|
logger = ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDERR))
|
|
|
|
logger.level = ActiveSupport::Logger::WARN
|
2010-01-23 10:07:20 -05:00
|
|
|
logger.warn(
|
|
|
|
"Rails Error: Unable to access log file. Please ensure that #{path} exists and is chmod 0666. " +
|
|
|
|
"The log level has been raised to WARN and the output directed to STDERR until the problem is fixed."
|
|
|
|
)
|
|
|
|
logger
|
|
|
|
end
|
2013-07-30 11:25:00 -04:00
|
|
|
|
2014-02-21 09:50:19 -05:00
|
|
|
Rails.logger.level = ActiveSupport::Logger.const_get(config.log_level.to_s.upcase)
|
2010-01-23 10:07:20 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
# Initialize cache early in the stack so railties can make use of it.
|
2012-10-14 06:03:39 -04:00
|
|
|
initializer :initialize_cache, group: :all do
|
2012-01-17 11:53:09 -05:00
|
|
|
unless Rails.cache
|
|
|
|
Rails.cache = ActiveSupport::Cache.lookup_store(config.cache_store)
|
2010-01-23 10:07:20 -05:00
|
|
|
|
2012-01-17 11:53:09 -05:00
|
|
|
if Rails.cache.respond_to?(:middleware)
|
|
|
|
config.middleware.insert_before("Rack::Runtime", Rails.cache.middleware)
|
2010-01-23 10:07:20 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Sets the dependency loading mechanism.
|
2012-10-14 06:03:39 -04:00
|
|
|
initializer :initialize_dependency_mechanism, group: :all do
|
2010-01-25 18:08:08 -05:00
|
|
|
ActiveSupport::Dependencies.mechanism = config.cache_classes ? :require : :load
|
2010-01-23 10:07:20 -05:00
|
|
|
end
|
2010-01-25 16:59:08 -05:00
|
|
|
|
2012-10-14 06:03:39 -04:00
|
|
|
initializer :bootstrap_hook, group: :all do |app|
|
2010-05-15 09:08:55 -04:00
|
|
|
ActiveSupport.run_load_hooks(:before_initialize, app)
|
2010-01-25 16:59:08 -05:00
|
|
|
end
|
2010-01-23 10:07:20 -05:00
|
|
|
end
|
|
|
|
end
|
2010-07-18 17:23:54 -04:00
|
|
|
end
|