Permalink
Newer
Older
100644 132 lines (118 sloc) 4.12 KB
1
require 'active_support/core_ext/string/encoding'
2
require 'rails/engine/configuration'
3
4
module Rails
5
class Application
6
class Configuration < ::Rails::Engine::Configuration
7
attr_accessor :allow_concurrency, :asset_host, :cache_classes, :cache_store,
8
:encoding, :consider_all_requests_local, :dependency_loading,
9
:filter_parameters, :helpers_paths, :logger,
10
:preload_frameworks, :reload_plugins,
11
:secret_token, :serve_static_assets, :session_options,
12
:time_zone, :whiny_nils, :force_ssl,
13
:asset_pipeline, :precompile_assets
17
def initialize(*)
18
super
21
@consider_all_requests_local = false
22
@filter_parameters = []
23
@helpers_paths = []
24
@dependency_loading = true
25
@serve_static_assets = true
27
@session_store = :cookie_store
28
@session_options = {}
29
@time_zone = "UTC"
30
@log_level = nil
31
@middleware = app_middleware
32
@generators = app_generators
33
@asset_pipeline = false
34
@precompile_assets = []
37
def compiled_asset_path
38
"/"
39
end
40
41
def encoding=(value)
42
@encoding = value
43
if "ruby".encoding_aware?
45
Encoding.default_internal = value
46
else
47
$KCODE = value
48
if $KCODE == "NONE"
49
raise "The value you specified for config.encoding is " \
50
"invalid. The possible values are UTF8, SJIS, or EUC"
51
end
53
end
54
55
def paths
56
@paths ||= begin
57
paths = super
58
paths.add "config/database", :with => "config/database.yml"
59
paths.add "config/environment", :with => "config/environment.rb"
60
paths.add "lib/templates"
61
paths.add "log", :with => "log/#{Rails.env}.log"
62
paths.add "tmp"
63
paths.add "tmp/cache"
64
paths
65
end
66
end
67
68
# Enable threaded mode. Allows concurrent requests to controller actions and
69
# multiple database connections. Also disables automatic dependency loading
70
# after boot, and disables reloading code on every request, as these are
71
# fundamentally incompatible with thread safety.
72
def threadsafe!
73
self.preload_frameworks = true
74
self.cache_classes = true
75
self.dependency_loading = false
76
self.allow_concurrency = true
77
self
78
end
79
80
# Loads and returns the contents of the #database_configuration_file. The
81
# contents of the file are processed via ERB before being sent through
82
# YAML::load.
83
def database_configuration
84
require 'erb'
85
YAML::load(ERB.new(IO.read(paths["config/database"].first)).result)
86
end
87
88
def cache_store
89
@cache_store ||= begin
90
if File.exist?("#{root}/tmp/cache/")
91
[ :file_store, "#{root}/tmp/cache/" ]
92
else
93
:memory_store
94
end
95
end
96
end
97
98
def log_level
99
@log_level ||= Rails.env.production? ? :info : :debug
100
end
101
102
def colorize_logging
103
@colorize_logging
104
end
105
106
def colorize_logging=(val)
107
@colorize_logging = val
108
ActiveSupport::LogSubscriber.colorize_logging = val
109
self.generators.colorize_logging = val
110
end
111
112
def session_store(*args)
113
if args.empty?
114
case @session_store
115
when :disabled
116
nil
117
when :active_record_store
118
ActiveRecord::SessionStore
119
when Symbol
120
ActionDispatch::Session.const_get(@session_store.to_s.camelize)
121
else
122
@session_store
123
end
124
else
125
@session_store = args.shift
126
@session_options = args.shift || {}
127
end
128
end
129
end
130
end