2011-08-24 19:23:24 -04:00
|
|
|
require 'active_support/core_ext/kernel/reporting'
|
2011-12-13 03:19:58 -05:00
|
|
|
require 'active_support/file_update_checker'
|
2010-01-23 16:30:17 -05:00
|
|
|
require 'rails/engine/configuration'
|
2014-03-16 15:57:21 -04:00
|
|
|
require 'rails/source_annotation_extractor'
|
2010-01-23 16:30:17 -05:00
|
|
|
|
|
|
|
module Rails
|
|
|
|
class Application
|
|
|
|
class Configuration < ::Rails::Engine::Configuration
|
2015-01-21 20:35:29 -05:00
|
|
|
attr_accessor :allow_concurrency, :asset_host, :autoflush_log,
|
2012-02-01 02:59:21 -05:00
|
|
|
:cache_classes, :cache_store, :consider_all_requests_local, :console,
|
2012-08-01 09:07:01 -04:00
|
|
|
:eager_load, :exceptions_app, :file_watcher, :filter_parameters,
|
2012-05-02 23:10:27 -04:00
|
|
|
:force_ssl, :helpers_paths, :logger, :log_formatter, :log_tags,
|
2012-11-02 18:27:51 -04:00
|
|
|
:railties_order, :relative_url_root, :secret_key_base, :secret_token,
|
2015-05-01 22:12:45 -04:00
|
|
|
:serve_static_files, :ssl_options, :static_index, :public_file_server,
|
2015-05-04 15:55:23 -04:00
|
|
|
:session_options, :time_zone, :reload_classes_only_on_change,
|
2015-04-20 12:28:23 -04:00
|
|
|
:beginning_of_week, :filter_redirect, :x
|
2010-01-23 16:30:17 -05:00
|
|
|
|
2015-01-04 09:35:20 -05:00
|
|
|
attr_writer :log_level
|
2015-05-01 22:12:45 -04:00
|
|
|
attr_reader :encoding, :api_only, :static_cache_control
|
2011-01-05 14:19:09 -05:00
|
|
|
|
2010-01-23 16:30:17 -05:00
|
|
|
def initialize(*)
|
|
|
|
super
|
2010-08-15 19:29:27 -04:00
|
|
|
self.encoding = "utf-8"
|
2013-03-03 15:20:44 -05:00
|
|
|
@allow_concurrency = nil
|
2011-12-12 16:51:33 -05:00
|
|
|
@consider_all_requests_local = false
|
|
|
|
@filter_parameters = []
|
2012-09-30 18:00:44 -04:00
|
|
|
@filter_redirect = []
|
2011-12-12 16:51:33 -05:00
|
|
|
@helpers_paths = []
|
2014-12-19 17:16:29 -05:00
|
|
|
@serve_static_files = true
|
2015-05-04 15:55:23 -04:00
|
|
|
@static_index = "index"
|
2015-05-01 22:12:45 -04:00
|
|
|
@public_file_server = ActiveSupport::OrderedOptions.new
|
2011-12-12 16:51:33 -05:00
|
|
|
@force_ssl = false
|
|
|
|
@ssl_options = {}
|
|
|
|
@session_store = :cookie_store
|
|
|
|
@session_options = {}
|
|
|
|
@time_zone = "UTC"
|
2012-09-18 10:18:19 -04:00
|
|
|
@beginning_of_week = :monday
|
2011-12-12 16:51:33 -05:00
|
|
|
@log_level = nil
|
|
|
|
@generators = app_generators
|
|
|
|
@cache_store = [ :file_store, "#{root}/tmp/cache/" ]
|
|
|
|
@railties_order = [:all]
|
|
|
|
@relative_url_root = ENV["RAILS_RELATIVE_URL_ROOT"]
|
|
|
|
@reload_classes_only_on_change = true
|
2011-12-13 03:19:58 -05:00
|
|
|
@file_watcher = ActiveSupport::FileUpdateChecker
|
2011-12-16 03:41:05 -05:00
|
|
|
@exceptions_app = nil
|
2012-02-22 18:38:34 -05:00
|
|
|
@autoflush_log = true
|
2012-03-12 17:25:25 -04:00
|
|
|
@log_formatter = ActiveSupport::Logger::SimpleFormatter.new
|
2012-08-01 09:07:01 -04:00
|
|
|
@eager_load = nil
|
2012-10-30 23:06:46 -04:00
|
|
|
@secret_token = nil
|
2012-11-02 18:27:51 -04:00
|
|
|
@secret_key_base = nil
|
2015-04-16 13:55:32 -04:00
|
|
|
@api_only = false
|
2014-08-19 18:41:15 -04:00
|
|
|
@x = Custom.new
|
2010-04-06 20:24:29 -04:00
|
|
|
end
|
|
|
|
|
2015-05-01 22:12:45 -04:00
|
|
|
def static_cache_control=(value)
|
|
|
|
ActiveSupport::Deprecation.warn("static_cache_control is deprecated and will be removed in Rails 5.1. " \
|
|
|
|
"Please use `config.public_file_server.headers = {'Cache-Control' => #{value}} " \
|
|
|
|
"instead.")
|
|
|
|
|
|
|
|
@static_cache_control = value
|
|
|
|
end
|
|
|
|
|
2010-04-06 20:24:29 -04:00
|
|
|
def encoding=(value)
|
|
|
|
@encoding = value
|
2011-12-24 07:57:54 -05:00
|
|
|
silence_warnings do
|
|
|
|
Encoding.default_external = value
|
|
|
|
Encoding.default_internal = value
|
2010-04-06 20:24:29 -04:00
|
|
|
end
|
2010-01-23 16:30:17 -05:00
|
|
|
end
|
|
|
|
|
2015-04-20 12:28:23 -04:00
|
|
|
def api_only=(value)
|
|
|
|
@api_only = value
|
|
|
|
generators.api_only = value
|
|
|
|
end
|
|
|
|
|
2010-01-23 16:30:17 -05:00
|
|
|
def paths
|
|
|
|
@paths ||= begin
|
|
|
|
paths = super
|
2012-10-14 06:03:39 -04:00
|
|
|
paths.add "config/database", with: "config/database.yml"
|
2013-12-12 14:58:53 -05:00
|
|
|
paths.add "config/secrets", with: "config/secrets.yml"
|
2012-10-14 06:03:39 -04:00
|
|
|
paths.add "config/environment", with: "config/environment.rb"
|
2010-10-06 11:18:59 -04:00
|
|
|
paths.add "lib/templates"
|
2012-10-14 06:03:39 -04:00
|
|
|
paths.add "log", with: "log/#{Rails.env}.log"
|
2011-04-15 13:57:52 -04:00
|
|
|
paths.add "public"
|
|
|
|
paths.add "public/javascripts"
|
|
|
|
paths.add "public/stylesheets"
|
2010-10-06 11:18:59 -04:00
|
|
|
paths.add "tmp"
|
2010-01-23 16:30:17 -05:00
|
|
|
paths
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-01-01 17:33:59 -05:00
|
|
|
# Loads and returns the entire raw configuration of database from
|
|
|
|
# values stored in `config/database.yml`.
|
2010-01-23 16:30:17 -05:00
|
|
|
def database_configuration
|
2014-09-10 06:25:01 -04:00
|
|
|
path = paths["config/database"].existent.first
|
|
|
|
yaml = Pathname.new(path) if path
|
2014-01-01 17:33:59 -05:00
|
|
|
|
2014-09-10 06:25:01 -04:00
|
|
|
config = if yaml && yaml.exist?
|
2014-03-29 16:21:01 -04:00
|
|
|
require "yaml"
|
2013-03-02 15:52:32 -05:00
|
|
|
require "erb"
|
2014-01-01 17:33:59 -05:00
|
|
|
YAML.load(ERB.new(yaml.read).result) || {}
|
2013-03-02 15:52:32 -05:00
|
|
|
elsif ENV['DATABASE_URL']
|
2014-01-01 17:33:59 -05:00
|
|
|
# Value from ENV['DATABASE_URL'] is set to default database connection
|
|
|
|
# by Active Record.
|
|
|
|
{}
|
2013-02-20 09:13:10 -05:00
|
|
|
else
|
2014-09-10 06:25:01 -04:00
|
|
|
raise "Could not load database configuration. No such file - #{paths["config/database"].instance_variable_get(:@paths)}"
|
2013-02-20 09:13:10 -05:00
|
|
|
end
|
2014-01-01 17:33:59 -05:00
|
|
|
|
|
|
|
config
|
2012-11-20 05:48:28 -05:00
|
|
|
rescue Psych::SyntaxError => e
|
|
|
|
raise "YAML syntax error occurred while parsing #{paths["config/database"].first}. " \
|
|
|
|
"Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \
|
|
|
|
"Error: #{e.message}"
|
2014-01-29 15:16:39 -05:00
|
|
|
rescue => e
|
|
|
|
raise e, "Cannot load `Rails.application.database_configuration`:\n#{e.message}", e.backtrace
|
2010-01-23 16:30:17 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def log_level
|
2014-11-17 07:17:23 -05:00
|
|
|
@log_level ||= (Rails.env.production? ? :info : :debug)
|
2010-01-23 16:30:17 -05:00
|
|
|
end
|
2010-03-02 16:05:25 -05:00
|
|
|
|
|
|
|
def colorize_logging
|
2012-01-27 09:01:14 -05:00
|
|
|
ActiveSupport::LogSubscriber.colorize_logging
|
2010-03-02 16:05:25 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def colorize_logging=(val)
|
2010-06-24 07:23:43 -04:00
|
|
|
ActiveSupport::LogSubscriber.colorize_logging = val
|
2010-03-02 16:05:25 -05:00
|
|
|
self.generators.colorize_logging = val
|
|
|
|
end
|
2010-03-26 13:47:55 -04:00
|
|
|
|
|
|
|
def session_store(*args)
|
|
|
|
if args.empty?
|
|
|
|
case @session_store
|
|
|
|
when :disabled
|
|
|
|
nil
|
2012-08-24 17:02:27 -04:00
|
|
|
when :active_record_store
|
|
|
|
begin
|
|
|
|
ActionDispatch::Session::ActiveRecordStore
|
|
|
|
rescue NameError
|
|
|
|
raise "`ActiveRecord::SessionStore` is extracted out of Rails into a gem. " \
|
|
|
|
"Please add `activerecord-session_store` to your Gemfile to use it."
|
|
|
|
end
|
2010-03-26 13:47:55 -04:00
|
|
|
when Symbol
|
|
|
|
ActionDispatch::Session.const_get(@session_store.to_s.camelize)
|
|
|
|
else
|
|
|
|
@session_store
|
|
|
|
end
|
|
|
|
else
|
|
|
|
@session_store = args.shift
|
|
|
|
@session_options = args.shift || {}
|
|
|
|
end
|
|
|
|
end
|
2011-12-20 14:18:23 -05:00
|
|
|
|
2014-03-16 15:57:21 -04:00
|
|
|
def annotations
|
|
|
|
SourceAnnotationExtractor::Annotation
|
|
|
|
end
|
2014-08-19 19:07:39 -04:00
|
|
|
|
2014-08-19 18:41:15 -04:00
|
|
|
private
|
2014-08-19 19:07:39 -04:00
|
|
|
class Custom #:nodoc:
|
2014-08-19 18:41:15 -04:00
|
|
|
def initialize
|
|
|
|
@configurations = Hash.new
|
|
|
|
end
|
2014-08-19 19:07:39 -04:00
|
|
|
|
2014-08-19 18:41:15 -04:00
|
|
|
def method_missing(method, *args)
|
2014-08-19 19:07:39 -04:00
|
|
|
if method =~ /=$/
|
|
|
|
@configurations[$`.to_sym] = args.first
|
|
|
|
else
|
|
|
|
@configurations.fetch(method) {
|
|
|
|
@configurations[method] = ActiveSupport::OrderedOptions.new
|
|
|
|
}
|
|
|
|
end
|
2014-08-19 18:41:15 -04:00
|
|
|
end
|
|
|
|
end
|
2010-01-23 16:30:17 -05:00
|
|
|
end
|
|
|
|
end
|
2010-03-20 13:34:21 -04:00
|
|
|
end
|