Skip to content
This repository
Newer
Older
100644 226 lines (194 sloc) 7.085 kb
6690d662 »
2010-04-05 Rename config.cookie_secret to config.secret_token and pass it as con…
1 require 'active_support/core_ext/hash/reverse_merge'
772c2b0b »
2010-06-20 Use the new ActiveSupport::FileUpdateChecker instead of RoutesReloader.
2 require 'active_support/file_update_checker'
02c5137e »
2010-01-22 Add view paths to Engine setup.
3 require 'fileutils'
b17e358e »
2010-01-23 Move configuration to subfolders.
4 require 'rails/plugin'
2fde9d77 »
2010-01-24 Solve some pendencies.
5 require 'rails/engine'
dc677f76 »
2009-12-22 tests pass with requiring the frameworks in rails.rb
6
accd9b46 »
2009-09-25 Restore "Start Rails::Application object
7 module Rails
781d0a9b »
2010-02-02 Add docs for Railtie, Engine, Plugin and Application.
8 # In Rails 3.0, a Rails::Application object was introduced which is nothing more than
9 # an Engine but with the responsibility of coordinating the whole boot process.
10 #
11 # Opposite to Rails::Engine, you can only have one Rails::Application instance
12 # in your process and both Rails::Application and YourApplication::Application
13 # points to it.
14 #
15 # In other words, Rails::Application is Singleton and whenever you are accessing
9cfeefb6 »
2010-05-15 Reorganized initializers a bit to enable better hooks for common case…
16 # Rails::Application.config or YourApplication::Application.config, you are actually
781d0a9b »
2010-02-02 Add docs for Railtie, Engine, Plugin and Application.
17 # accessing YourApplication::Application.instance.config.
18 #
19 # == Initialization
20 #
21 # Rails::Application is responsible for executing all railties, engines and plugin
22 # initializers. Besides, it also executed some bootstrap initializers (check
23 # Rails::Application::Bootstrap) and finishing initializers, after all the others
24 # are executed (check Rails::Application::Finisher).
25 #
26 # == Configuration
27 #
28 # Besides providing the same configuration as Rails::Engine and Rails::Railtie,
29 # the application object has several specific configurations, for example
30 # "allow_concurrency", "cache_classes", "consider_all_requests_local", "filter_parameters",
45e60283 »
2010-05-29 Removing Metal from Rails 3.
31 # "logger", "reload_engines", "reload_plugins" and so forth.
781d0a9b »
2010-02-02 Add docs for Railtie, Engine, Plugin and Application.
32 #
33 # Check Rails::Application::Configuration to see them all.
34 #
35 # == Routes
36 #
37 # The application object is also responsible for holding the routes and reloading routes
38 # whenever the files change in development.
39 #
45e60283 »
2010-05-29 Removing Metal from Rails 3.
40 # == Middlewares
781d0a9b »
2010-02-02 Add docs for Railtie, Engine, Plugin and Application.
41 #
45e60283 »
2010-05-29 Removing Metal from Rails 3.
42 # The Application is also responsible for building the middleware stack.
9cfeefb6 »
2010-05-15 Reorganized initializers a bit to enable better hooks for common case…
43 #
7fcf8590 »
2010-01-21 Massive cleanup in Railties and load stack.
44 class Application < Engine
4f036032 »
2010-01-23 Break application.rb file in smaller chunks.
45 autoload :Bootstrap, 'rails/application/bootstrap'
f8bf1982 »
2010-01-26 Add tests for explicit engines.
46 autoload :Configurable, 'rails/application/configurable'
b17e358e »
2010-01-23 Move configuration to subfolders.
47 autoload :Configuration, 'rails/application/configuration'
4f036032 »
2010-01-23 Break application.rb file in smaller chunks.
48 autoload :Finisher, 'rails/application/finisher'
13d66cdf »
2010-01-23 Extract Railtie load from application.
49 autoload :Railties, 'rails/application/railties'
80130d12 »
2010-01-23 Extract routes reloading responsibilities from application and load t…
50
e4d7e509 »
2009-10-08 Moving more initializers into the application object
51 class << self
94bb3316 »
2009-12-23 Shift more responsibility from application class to its singleton ins…
52 private :new
79b0b508 »
2010-03-07 Aliasing class_eval makes JRuby ornery.
53
54 def configure(&block)
55 class_eval(&block)
56 end
80130d12 »
2010-01-23 Extract routes reloading responsibilities from application and load t…
57
94bb3316 »
2009-12-23 Shift more responsibility from application class to its singleton ins…
58 def instance
db99324a »
2010-01-26 Ensure calling a method in Rails::Application does not instantiate a …
59 if self == Rails::Application
60 Rails.application
92126521 »
2010-01-24 Add Rails::Application pointer to the default app to add symmetry to …
61 else
db99324a »
2010-01-26 Ensure calling a method in Rails::Application does not instantiate a …
62 @@instance ||= new
92126521 »
2010-01-24 Add Rails::Application pointer to the default app to add symmetry to …
63 end
897164dd »
2009-11-02 Conceptually unify instance & global initializers
64 end
65
7fcf8590 »
2010-01-21 Massive cleanup in Railties and load stack.
66 def inherited(base)
2fde9d77 »
2010-01-24 Solve some pendencies.
67 raise "You cannot have more than one Rails::Application" if Rails.application
7fcf8590 »
2010-01-21 Massive cleanup in Railties and load stack.
68 super
788fce25 »
2010-01-23 Create configurable modules and ensure that they are added only on di…
69 Rails.application = base.instance
5a0d73f1 »
2010-06-02 Add lib to load paths when application is inherited to be able to loa…
70 Rails.application.add_lib_to_load_paths!
9cfeefb6 »
2010-05-15 Reorganized initializers a bit to enable better hooks for common case…
71 ActiveSupport.run_load_hooks(:before_configuration, base.instance)
e4d7e509 »
2009-10-08 Moving more initializers into the application object
72 end
6f6a589d »
2009-09-28 Create the application object from config/environment.rb
73
e7418ab6 »
2010-01-27 Add more tests to some key points in Railties.
74 def respond_to?(*args)
75 super || instance.respond_to?(*args)
76 end
77
80130d12 »
2010-01-23 Extract routes reloading responsibilities from application and load t…
78 protected
79
80 def method_missing(*args, &block)
81 instance.send(*args, &block)
426348b4 »
2009-12-21 Update routes.rb template to use App name
82 end
897164dd »
2009-11-02 Conceptually unify instance & global initializers
83 end
6f6a589d »
2009-09-28 Create the application object from config/environment.rb
84
45e60283 »
2010-05-29 Removing Metal from Rails 3.
85 delegate :middleware, :to => :config
395d6648 »
2010-03-26 Move application configuration to the application configuration objec…
86
9e081cae »
2010-06-20 Improve documentation for add_lib_to_load_paths!
87 # This method is called just after an application inherits from Rails::Application,
88 # allowing the developer to load classes in lib and use them during application
89 # configuration.
90 #
91 # class MyApplication < Rails::Application
92 # require "my_backend" # in lib/my_backend
93 # config.i18n.backend = MyBackend
94 # end
95 #
96 # Notice this method takes into consideration the default root path. So if you
97 # are changing config.root inside your application definition or having a custom
98 # Rails application, you will need to add lib to $LOAD_PATH on your own in case
99 # you need to load files in lib/ during the application configuration as well.
100 def add_lib_to_load_paths! #:nodoc:
5a0d73f1 »
2010-06-02 Add lib to load paths when application is inherited to be able to loa…
101 path = config.root.join('lib').to_s
102 $LOAD_PATH.unshift(path) if File.exists?(path)
103 end
104
9e081cae »
2010-06-20 Improve documentation for add_lib_to_load_paths!
105 def require_environment! #:nodoc:
1b816d50 »
2010-04-29 The rake task :environment now loads config/environment.rb instead of…
106 environment = paths.config.environment.to_a.first
13d66cdf »
2010-01-23 Extract Railtie load from application.
107 require environment if environment
d982fe2b »
2009-12-21 Replace reopening the class with App.configure as an alias to class_eval
108 end
109
9e081cae »
2010-06-20 Improve documentation for add_lib_to_load_paths!
110 def eager_load! #:nodoc:
5a0d73f1 »
2010-06-02 Add lib to load paths when application is inherited to be able to loa…
111 railties.all(&:eager_load!)
112 super
113 end
114
80130d12 »
2010-01-23 Extract routes reloading responsibilities from application and load t…
115 def routes
9a5be2e5 »
2010-02-24 Get Railties tests passing
116 @routes ||= ActionDispatch::Routing::RouteSet.new
13d66cdf »
2010-01-23 Extract Railtie load from application.
117 end
118
119 def railties
120 @railties ||= Railties.new(config)
897164dd »
2009-11-02 Conceptually unify instance & global initializers
121 end
5f8e48cb »
2009-12-14 Move route reloading into railties
122
80130d12 »
2010-01-23 Extract routes reloading responsibilities from application and load t…
123 def routes_reloader
772c2b0b »
2010-06-20 Use the new ActiveSupport::FileUpdateChecker instead of RoutesReloader.
124 @routes_reloader ||= ActiveSupport::FileUpdateChecker.new([]){ reload_routes! }
5f8e48cb »
2009-12-14 Move route reloading into railties
125 end
126
127 def reload_routes!
772c2b0b »
2010-06-20 Use the new ActiveSupport::FileUpdateChecker instead of RoutesReloader.
128 routes = Rails::Application.routes
129 routes.disable_clear_and_finalize = true
130
131 routes.clear!
132 routes_reloader.paths.each { |path| load(path) }
133 ActiveSupport.on_load(:action_controller) { routes.finalize! }
134 ensure
135 routes.disable_clear_and_finalize = false
80130d12 »
2010-01-23 Extract routes reloading responsibilities from application and load t…
136 end
5f8e48cb »
2009-12-14 Move route reloading into railties
137
80130d12 »
2010-01-23 Extract routes reloading responsibilities from application and load t…
138 def initialize!
139 run_initializers(self)
140 self
5f8e48cb »
2009-12-14 Move route reloading into railties
141 end
142
94bb3316 »
2009-12-23 Shift more responsibility from application class to its singleton ins…
143 def load_tasks
788fce25 »
2010-01-23 Create configurable modules and ensure that they are added only on di…
144 initialize_tasks
13d66cdf »
2010-01-23 Extract Railtie load from application.
145 railties.all { |r| r.load_tasks }
e461e1bc »
2010-04-26 Ensure application rake tasks and generators are loaded after the one…
146 super
13d66cdf »
2010-01-23 Extract Railtie load from application.
147 self
94bb3316 »
2009-12-23 Shift more responsibility from application class to its singleton ins…
148 end
149
4ca97650 »
2010-01-19 Allow railties to specify generators paths.
150 def load_generators
788fce25 »
2010-01-23 Create configurable modules and ensure that they are added only on di…
151 initialize_generators
13d66cdf »
2010-01-23 Extract Railtie load from application.
152 railties.all { |r| r.load_generators }
e461e1bc »
2010-04-26 Ensure application rake tasks and generators are loaded after the one…
153 super
13d66cdf »
2010-01-23 Extract Railtie load from application.
154 self
82b9b151 »
2009-11-06 Refactor plugins
155 end
156
603d4fba »
2010-01-16 Build middleware stack and reload routes after app initializers run
157 def app
19d8c8cb »
2010-05-29 Remove the laziness from the middleware stack.
158 @app ||= begin
159 config.middleware = config.middleware.merge_into(default_middleware_stack)
160 config.middleware.build(routes)
161 end
603d4fba »
2010-01-16 Build middleware stack and reload routes after app initializers run
162 end
163
897164dd »
2009-11-02 Conceptually unify instance & global initializers
164 def call(env)
6690d662 »
2010-04-05 Rename config.cookie_secret to config.secret_token and pass it as con…
165 app.call(env.reverse_merge!(env_defaults))
166 end
167
168 def env_defaults
169 @env_defaults ||= {
170 "action_dispatch.parameter_filter" => config.filter_parameters,
171 "action_dispatch.secret_token" => config.secret_token
172 }
6d6ae084 »
2009-10-07 Start moving the initializers into the application object
173 end
174
98240c49 »
2010-01-23 Get rid of initializers global and create i18n railtie.
175 def initializers
5d078692 »
2010-01-26 Ensure all initializers are collections.
176 initializers = Bootstrap.initializers_for(self)
13d66cdf »
2010-01-23 Extract Railtie load from application.
177 railties.all { |r| initializers += r.initializers }
2d1f9fb9 »
2010-01-25 Plugins need to load before app initializers
178 initializers += super
5d078692 »
2010-01-26 Ensure all initializers are collections.
179 initializers += Finisher.initializers_for(self)
98240c49 »
2010-01-23 Get rid of initializers global and create i18n railtie.
180 initializers
181 end
788fce25 »
2010-01-23 Create configurable modules and ensure that they are added only on di…
182
183 protected
184
19d8c8cb »
2010-05-29 Remove the laziness from the middleware stack.
185 def default_middleware_stack
186 ActionDispatch::MiddlewareStack.new.tap do |middleware|
187 middleware.use ::ActionDispatch::Static, paths.public.to_a.first if config.serve_static_assets
188 middleware.use ::Rack::Lock if !config.allow_concurrency
189 middleware.use ::Rack::Runtime
190 middleware.use ::Rails::Rack::Logger
191 middleware.use ::ActionDispatch::ShowExceptions, config.consider_all_requests_local if config.action_dispatch.show_exceptions
192 middleware.use ::ActionDispatch::RemoteIp, config.action_dispatch.ip_spoofing_check, config.action_dispatch.trusted_proxies
193 middleware.use ::Rack::Sendfile, config.action_dispatch.x_sendfile_header
194 middleware.use ::ActionDispatch::Callbacks, !config.cache_classes
195 middleware.use ::ActionDispatch::Cookies
196
197 if config.session_store
198 middleware.use config.session_store, config.session_options
199 middleware.use ::ActionDispatch::Flash
200 end
201
202 middleware.use ::ActionDispatch::ParamsParser
203 middleware.use ::Rack::MethodOverride
204 middleware.use ::ActionDispatch::Head
205 end
206 end
207
788fce25 »
2010-01-23 Create configurable modules and ensure that they are added only on di…
208 def initialize_tasks
209 require "rails/tasks"
210 task :environment do
211 $rails_rake_task = true
1b816d50 »
2010-04-29 The rake task :environment now loads config/environment.rb instead of…
212 require_environment!
788fce25 »
2010-01-23 Create configurable modules and ensure that they are added only on di…
213 end
214 end
215
216 def initialize_generators
217 require "rails/generators"
218 end
219
220 # Application is always reloadable when config.cache_classes is false.
221 def reloadable?(app)
222 true
223 end
accd9b46 »
2009-09-25 Restore "Start Rails::Application object
224 end
225 end
Something went wrong with that request. Please try again.