Skip to content
This repository
Newer
Older
100644 150 lines (131 sloc) 5.548 kb
b17e358e » josevalim
2010-01-23 Move configuration to subfolders.
1 require 'rails/engine/configuration'
2
3 module Rails
4 class Application
5 class Configuration < ::Rails::Engine::Configuration
6 include ::Rails::Configuration::Deprecated
7
c2dbc391 » Carlhuda
2010-03-02 Have log subscribers subscribe to the actual events, so the subscribe…
8 attr_accessor :allow_concurrency, :cache_classes, :cache_store,
395d6648 » josevalim
2010-03-26 Move application configuration to the application configuration objec…
9 :cookie_secret, :consider_all_requests_local, :dependency_loading,
b17e358e » josevalim
2010-01-23 Move configuration to subfolders.
10 :filter_parameters, :log_level, :logger, :metals,
64ea3dfd » josevalim
2010-01-27 Add reloadable specific for engines and move environment to applicati…
11 :plugins, :preload_frameworks, :reload_engines, :reload_plugins,
b17e358e » josevalim
2010-01-23 Move configuration to subfolders.
12 :serve_static_assets, :time_zone, :whiny_nils
13
14 def initialize(*)
15 super
0dece792 » josevalim
2010-02-01 Deprecate AC configuration values which were moved to Rack.
16 @allow_concurrency = false
b17e358e » josevalim
2010-01-23 Move configuration to subfolders.
17 @filter_parameters = []
18 @dependency_loading = true
19 @serve_static_assets = true
64ea3dfd » josevalim
2010-01-27 Add reloadable specific for engines and move environment to applicati…
20 @time_zone = "UTC"
0dece792 » josevalim
2010-02-01 Deprecate AC configuration values which were moved to Rack.
21 @consider_all_requests_local = true
395d6648 » josevalim
2010-03-26 Move application configuration to the application configuration objec…
22 @session_store = :cookie_store
23 @session_options = {}
b17e358e » josevalim
2010-01-23 Move configuration to subfolders.
24 end
25
ae93789d » Carlhuda
2010-03-08 Move middlewares to the Application level. If you want to modify the …
26 def middleware
395d6648 » josevalim
2010-03-26 Move application configuration to the application configuration objec…
27 @middleware ||= default_middleware_stack
28 end
29
30 def metal_loader
31 @metal_loader ||= Rails::Application::MetalLoader.new
ae93789d » Carlhuda
2010-03-08 Move middlewares to the Application level. If you want to modify the …
32 end
33
b17e358e » josevalim
2010-01-23 Move configuration to subfolders.
34 def paths
35 @paths ||= begin
36 paths = super
37 paths.app.controllers << builtin_controller if builtin_controller
38 paths.config.database "config/database.yml"
64ea3dfd » josevalim
2010-01-27 Add reloadable specific for engines and move environment to applicati…
39 paths.config.environment "config/environments", :glob => "#{Rails.env}.rb"
b17e358e » josevalim
2010-01-23 Move configuration to subfolders.
40 paths.log "log/#{Rails.env}.log"
41 paths.tmp "tmp"
42 paths.tmp.cache "tmp/cache"
43 paths.vendor "vendor", :load_path => true
44 paths.vendor.plugins "vendor/plugins"
45
46 if File.exists?("#{root}/test/mocks/#{Rails.env}")
47 ActiveSupport::Deprecation.warn "\"RAILS_ROOT/test/mocks/#{Rails.env}\" won't be added " <<
48 "automatically to load paths anymore in future releases"
49 paths.mocks_path "test/mocks", :load_path => true, :glob => Rails.env
50 end
51
52 paths
53 end
54 end
55
56 # Enable threaded mode. Allows concurrent requests to controller actions and
57 # multiple database connections. Also disables automatic dependency loading
58 # after boot, and disables reloading code on every request, as these are
59 # fundamentally incompatible with thread safety.
60 def threadsafe!
61 self.preload_frameworks = true
62 self.cache_classes = true
63 self.dependency_loading = false
0dece792 » josevalim
2010-02-01 Deprecate AC configuration values which were moved to Rack.
64 self.allow_concurrency = true
b17e358e » josevalim
2010-01-23 Move configuration to subfolders.
65 self
66 end
67
68 # Loads and returns the contents of the #database_configuration_file. The
69 # contents of the file are processed via ERB before being sent through
70 # YAML::load.
71 def database_configuration
72 require 'erb'
73 YAML::load(ERB.new(IO.read(paths.config.database.to_a.first)).result)
74 end
75
76 def cache_store
77 @cache_store ||= begin
78 if File.exist?("#{root}/tmp/cache/")
79 [ :file_store, "#{root}/tmp/cache/" ]
80 else
81 :memory_store
82 end
83 end
84 end
85
86 def builtin_controller
f38e89cf » josh
2010-03-20 Move railties/builtin into lib
87 File.expand_path('../info_routes', __FILE__) if Rails.env.development?
b17e358e » josevalim
2010-01-23 Move configuration to subfolders.
88 end
89
90 def log_level
91 @log_level ||= Rails.env.production? ? :info : :debug
92 end
c2dbc391 » Carlhuda
2010-03-02 Have log subscribers subscribe to the actual events, so the subscribe…
93
94 def colorize_logging
95 @colorize_logging
96 end
97
98 def colorize_logging=(val)
99 @colorize_logging = val
100 Rails::LogSubscriber.colorize_logging = val
101 self.generators.colorize_logging = val
102 end
395d6648 » josevalim
2010-03-26 Move application configuration to the application configuration objec…
103
104 def session_store(*args)
105 if args.empty?
106 case @session_store
107 when :disabled
108 nil
109 when :active_record_store
110 ActiveRecord::SessionStore
111 when Symbol
112 ActionDispatch::Session.const_get(@session_store.to_s.camelize)
113 else
114 @session_store
115 end
116 else
117 @session_store = args.shift
118 @session_options = args.shift || {}
119 end
120 end
121
122 protected
123
124 def session_options
125 return @session_options unless @session_store == :cookie_store
126 @session_options.merge(:secret => @cookie_secret)
127 end
128
129 def default_middleware_stack
130 ActionDispatch::MiddlewareStack.new.tap do |middleware|
131 middleware.use('::ActionDispatch::Static', lambda { Rails.public_path }, :if => lambda { serve_static_assets })
132 middleware.use('::Rack::Lock', :if => lambda { !allow_concurrency })
133 middleware.use('::Rack::Runtime')
134 middleware.use('::Rails::Rack::Logger')
d898a4ba » rolfb
2010-04-02 Raise exceptions instead of rendering error templates in test environ…
135 middleware.use('::ActionDispatch::ShowExceptions', lambda { consider_all_requests_local }, :if => lambda { action_dispatch.show_exceptions })
395d6648 » josevalim
2010-03-26 Move application configuration to the application configuration objec…
136 middleware.use("::ActionDispatch::RemoteIp", lambda { action_dispatch.ip_spoofing_check }, lambda { action_dispatch.trusted_proxies })
137 middleware.use('::Rack::Sendfile', lambda { action_dispatch.x_sendfile_header })
138 middleware.use('::ActionDispatch::Callbacks', lambda { !cache_classes })
139 middleware.use('::ActionDispatch::Cookies')
140 middleware.use(lambda { session_store }, lambda { session_options })
141 middleware.use('::ActionDispatch::Flash', :if => lambda { session_store })
142 middleware.use(lambda { metal_loader.build_middleware(metals) }, :if => lambda { metal_loader.metals.any? })
143 middleware.use('ActionDispatch::ParamsParser')
144 middleware.use('::Rack::MethodOverride')
145 middleware.use('::ActionDispatch::Head')
146 end
147 end
b17e358e » josevalim
2010-01-23 Move configuration to subfolders.
148 end
149 end
f38e89cf » josh
2010-03-20 Move railties/builtin into lib
150 end
Something went wrong with that request. Please try again.