Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 126 lines (102 sloc) 2.775 kb
02c5137 @josevalim Add view paths to Engine setup.
josevalim authored
1 require 'fileutils'
b17e358 @josevalim Move configuration to subfolders.
josevalim authored
2 require 'rails/railties_path'
3 require 'rails/plugin'
2fde9d7 @josevalim Solve some pendencies.
josevalim authored
4 require 'rails/engine'
dc677f7 tests pass with requiring the frameworks in rails.rb
Carlhuda authored
5
accd9b4 @josh Restore "Start Rails::Application object
josh authored
6 module Rails
7fcf859 @josevalim Massive cleanup in Railties and load stack.
josevalim authored
7 class Application < Engine
4f03603 @josevalim Break application.rb file in smaller chunks.
josevalim authored
8 autoload :Bootstrap, 'rails/application/bootstrap'
f8bf198 @josevalim Add tests for explicit engines.
josevalim authored
9 autoload :Configurable, 'rails/application/configurable'
b17e358 @josevalim Move configuration to subfolders.
josevalim authored
10 autoload :Configuration, 'rails/application/configuration'
4f03603 @josevalim Break application.rb file in smaller chunks.
josevalim authored
11 autoload :Finisher, 'rails/application/finisher'
226d8e7 @josevalim Refactor MetalLoader and RoutesReloader to rely less on class configurat...
josevalim authored
12 autoload :MetalLoader, 'rails/application/metal_loader'
13d66cd @josevalim Extract Railtie load from application.
josevalim authored
13 autoload :Railties, 'rails/application/railties'
80130d1 @josevalim Extract routes reloading responsibilities from application and load them...
josevalim authored
14 autoload :RoutesReloader, 'rails/application/routes_reloader'
15
e4d7e50 Moving more initializers into the application object
Carl Lerche authored
16 class << self
94bb331 @jeremy Shift more responsibility from application class to its singleton instan...
jeremy authored
17 private :new
80130d1 @josevalim Extract routes reloading responsibilities from application and load them...
josevalim authored
18 alias :configure :class_eval
19
94bb331 @jeremy Shift more responsibility from application class to its singleton instan...
jeremy authored
20 def instance
db99324 @josevalim Ensure calling a method in Rails::Application does not instantiate a voi...
josevalim authored
21 if self == Rails::Application
22 Rails.application
9212652 @josh Add Rails::Application pointer to the default app to add symmetry to Foo...
josh authored
23 else
db99324 @josevalim Ensure calling a method in Rails::Application does not instantiate a voi...
josevalim authored
24 @@instance ||= new
9212652 @josh Add Rails::Application pointer to the default app to add symmetry to Foo...
josh authored
25 end
897164d Conceptually unify instance & global initializers
Yehuda Katz + Carl Lerche authored
26 end
27
7fcf859 @josevalim Massive cleanup in Railties and load stack.
josevalim authored
28 def inherited(base)
2fde9d7 @josevalim Solve some pendencies.
josevalim authored
29 raise "You cannot have more than one Rails::Application" if Rails.application
7fcf859 @josevalim Massive cleanup in Railties and load stack.
josevalim authored
30 super
788fce2 @josevalim Create configurable modules and ensure that they are added only on direc...
josevalim authored
31 Rails.application = base.instance
e4d7e50 Moving more initializers into the application object
Carl Lerche authored
32 end
6f6a589 Create the application object from config/environment.rb
Yehuda Katz + Carl Lerche authored
33
e7418ab @josevalim Add more tests to some key points in Railties.
josevalim authored
34 def respond_to?(*args)
35 super || instance.respond_to?(*args)
36 end
37
80130d1 @josevalim Extract routes reloading responsibilities from application and load them...
josevalim authored
38 protected
39
40 def method_missing(*args, &block)
41 instance.send(*args, &block)
426348b @josh Update routes.rb template to use App name
josh authored
42 end
897164d Conceptually unify instance & global initializers
Yehuda Katz + Carl Lerche authored
43 end
6f6a589 Create the application object from config/environment.rb
Yehuda Katz + Carl Lerche authored
44
788fce2 @josevalim Create configurable modules and ensure that they are added only on direc...
josevalim authored
45 def require_environment!
13d66cd @josevalim Extract Railtie load from application.
josevalim authored
46 environment = config.paths.config.environment.to_a.first
47 require environment if environment
d982fe2 Replace reopening the class with App.configure as an alias to class_eval
Carlhuda authored
48 end
49
80130d1 @josevalim Extract routes reloading responsibilities from application and load them...
josevalim authored
50 def routes
9a5be2e Get Railties tests passing
Carlhuda authored
51 @routes ||= ActionDispatch::Routing::RouteSet.new
13d66cd @josevalim Extract Railtie load from application.
josevalim authored
52 end
53
54 def railties
55 @railties ||= Railties.new(config)
897164d Conceptually unify instance & global initializers
Yehuda Katz + Carl Lerche authored
56 end
5f8e48c @josh Move route reloading into railties
josh authored
57
226d8e7 @josevalim Refactor MetalLoader and RoutesReloader to rely less on class configurat...
josevalim authored
58 def metal_loader
4cdfe98 @MSch Typo
MSch authored
59 @metal_loader ||= MetalLoader.new
226d8e7 @josevalim Refactor MetalLoader and RoutesReloader to rely less on class configurat...
josevalim authored
60 end
61
80130d1 @josevalim Extract routes reloading responsibilities from application and load them...
josevalim authored
62 def routes_reloader
226d8e7 @josevalim Refactor MetalLoader and RoutesReloader to rely less on class configurat...
josevalim authored
63 @routes_reloader ||= RoutesReloader.new
5f8e48c @josh Move route reloading into railties
josh authored
64 end
65
66 def reload_routes!
80130d1 @josevalim Extract routes reloading responsibilities from application and load them...
josevalim authored
67 routes_reloader.reload!
68 end
5f8e48c @josh Move route reloading into railties
josh authored
69
80130d1 @josevalim Extract routes reloading responsibilities from application and load them...
josevalim authored
70 def initialize!
71 run_initializers(self)
72 self
5f8e48c @josh Move route reloading into railties
josh authored
73 end
74
94bb331 @jeremy Shift more responsibility from application class to its singleton instan...
jeremy authored
75 def load_tasks
788fce2 @josevalim Create configurable modules and ensure that they are added only on direc...
josevalim authored
76 initialize_tasks
13d66cd @josevalim Extract Railtie load from application.
josevalim authored
77 super
78 railties.all { |r| r.load_tasks }
79 self
94bb331 @jeremy Shift more responsibility from application class to its singleton instan...
jeremy authored
80 end
81
4ca9765 @josevalim Allow railties to specify generators paths.
josevalim authored
82 def load_generators
788fce2 @josevalim Create configurable modules and ensure that they are added only on direc...
josevalim authored
83 initialize_generators
13d66cd @josevalim Extract Railtie load from application.
josevalim authored
84 super
85 railties.all { |r| r.load_generators }
86 self
82b9b15 Refactor plugins
Yehuda Katz + Carl Lerche authored
87 end
88
603d4fb @josh Build middleware stack and reload routes after app initializers run
josh authored
89 def app
80130d1 @josevalim Extract routes reloading responsibilities from application and load them...
josevalim authored
90 @app ||= middleware.build(routes)
603d4fb @josh Build middleware stack and reload routes after app initializers run
josh authored
91 end
92
897164d Conceptually unify instance & global initializers
Yehuda Katz + Carl Lerche authored
93 def call(env)
fc4f237 @josevalim Make filter parameters based on request, so they can be modified for any...
josevalim authored
94 env["action_dispatch.parameter_filter"] = config.filter_parameters
603d4fb @josh Build middleware stack and reload routes after app initializers run
josh authored
95 app.call(env)
6d6ae08 Start moving the initializers into the application object
Carl Lerche authored
96 end
97
98240c4 @josevalim Get rid of initializers global and create i18n railtie.
josevalim authored
98 def initializers
5d07869 @josevalim Ensure all initializers are collections.
josevalim authored
99 initializers = Bootstrap.initializers_for(self)
13d66cd @josevalim Extract Railtie load from application.
josevalim authored
100 railties.all { |r| initializers += r.initializers }
2d1f9fb @josh Plugins need to load before app initializers
josh authored
101 initializers += super
5d07869 @josevalim Ensure all initializers are collections.
josevalim authored
102 initializers += Finisher.initializers_for(self)
98240c4 @josevalim Get rid of initializers global and create i18n railtie.
josevalim authored
103 initializers
104 end
788fce2 @josevalim Create configurable modules and ensure that they are added only on direc...
josevalim authored
105
106 protected
107
108 def initialize_tasks
109 require "rails/tasks"
110 task :environment do
111 $rails_rake_task = true
112 initialize!
113 end
114 end
115
116 def initialize_generators
117 require "rails/generators"
118 end
119
120 # Application is always reloadable when config.cache_classes is false.
121 def reloadable?(app)
122 true
123 end
accd9b4 @josh Restore "Start Rails::Application object
josh authored
124 end
125 end
Something went wrong with that request. Please try again.