Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 156 lines (127 sloc) 3.867 kB
dc677f7 tests pass with requiring the frameworks in rails.rb
Carlhuda authored
1 require "fileutils"
94bb331 @jeremy Shift more responsibility from application class to its singleton ins…
jeremy authored
2 require 'active_support/core_ext/module/delegation'
dc677f7 tests pass with requiring the frameworks in rails.rb
Carlhuda authored
3
accd9b4 @josh Restore "Start Rails::Application object
josh authored
4 module Rails
5 class Application
897164d Conceptually unify instance & global initializers
Yehuda Katz + Carl Lerche authored
6 include Initializable
6d6ae08 Start moving the initializers into the application object
Carl Lerche authored
7
e4d7e50 Moving more initializers into the application object
Carl Lerche authored
8 class << self
94bb331 @jeremy Shift more responsibility from application class to its singleton ins…
jeremy authored
9 attr_writer :config
10 alias configure class_eval
4ca9765 @josevalim Allow railties to specify generators paths.
josevalim authored
11 delegate :initialize!, :load_tasks, :load_generators, :root, :to => :instance
d859402 @josh Use Rails.initialize! where we just want to run the initializers and …
josh authored
12
94bb331 @jeremy Shift more responsibility from application class to its singleton ins…
jeremy authored
13 private :new
14 def instance
15 @instance ||= new
897164d Conceptually unify instance & global initializers
Yehuda Katz + Carl Lerche authored
16 end
17
e4d7e50 Moving more initializers into the application object
Carl Lerche authored
18 def config
38aeb15 Moving out some framework specific initializers into the framework li…
Carlhuda authored
19 @config ||= Configuration.new(Plugin::Configuration.default)
e4d7e50 Moving more initializers into the application object
Carl Lerche authored
20 end
6f6a589 Create the application object from config/environment.rb
Yehuda Katz + Carl Lerche authored
21
426348b @josh Update routes.rb template to use App name
josh authored
22 def routes
23 ActionController::Routing::Routes
24 end
897164d Conceptually unify instance & global initializers
Yehuda Katz + Carl Lerche authored
25 end
6f6a589 Create the application object from config/environment.rb
Yehuda Katz + Carl Lerche authored
26
94bb331 @jeremy Shift more responsibility from application class to its singleton ins…
jeremy authored
27 delegate :config, :routes, :to => :'self.class'
28 delegate :root, :middleware, :to => :config
5f8e48c @josh Move route reloading into railties
josh authored
29 attr_reader :route_configuration_files
30
897164d Conceptually unify instance & global initializers
Yehuda Katz + Carl Lerche authored
31 def initialize
94bb331 @jeremy Shift more responsibility from application class to its singleton ins…
jeremy authored
32 require_environment
530b8ff Have script/* and Rakefile use the application object
Carlhuda authored
33 Rails.application ||= self
5f8e48c @josh Move route reloading into railties
josh authored
34 @route_configuration_files = []
d982fe2 Replace reopening the class with App.configure as an alias to class_eval
Carlhuda authored
35 end
36
94bb331 @jeremy Shift more responsibility from application class to its singleton ins…
jeremy authored
37 def initialize!
38 run_initializers(self)
39 self
897164d Conceptually unify instance & global initializers
Yehuda Katz + Carl Lerche authored
40 end
41
94bb331 @jeremy Shift more responsibility from application class to its singleton ins…
jeremy authored
42 def require_environment
43 require config.environment_path
44 rescue LoadError
897164d Conceptually unify instance & global initializers
Yehuda Katz + Carl Lerche authored
45 end
46
5f8e48c @josh Move route reloading into railties
josh authored
47 def routes_changed_at
48 routes_changed_at = nil
49
50 route_configuration_files.each do |config|
51 config_changed_at = File.stat(config).mtime
52
53 if routes_changed_at.nil? || config_changed_at > routes_changed_at
54 routes_changed_at = config_changed_at
55 end
56 end
57
58 routes_changed_at
59 end
60
61 def reload_routes!
62 routes.disable_clear_and_finalize = true
63
64 routes.clear!
65 route_configuration_files.each { |config| load(config) }
66 routes.finalize!
67
68 nil
69 ensure
70 routes.disable_clear_and_finalize = false
71 end
72
94bb331 @jeremy Shift more responsibility from application class to its singleton ins…
jeremy authored
73 def load_tasks
74 require "rails/tasks"
468bdb3 @spohlenz Make plugins responsible for loading their own rake tasks
spohlenz authored
75 plugins.each { |p| p.load_tasks }
c02f278 Add the ability to have plugins load rake tasks.
Carl Lerche authored
76 # Load all application tasks
77 # TODO: extract out the path to the rake tasks
94bb331 @jeremy Shift more responsibility from application class to its singleton ins…
jeremy authored
78 Dir["#{root}/lib/tasks/**/*.rake"].sort.each { |ext| load ext }
79 task :environment do
80 $rails_rake_task = true
81 initialize!
82 end
83 end
84
4ca9765 @josevalim Allow railties to specify generators paths.
josevalim authored
85 def load_generators
86 plugins.each { |p| p.load_generators }
87 end
88
82b9b15 Refactor plugins
Yehuda Katz + Carl Lerche authored
89 def initializers
8fe66f1 @josh Run railtie and plugin initializers before app specific ones
josh authored
90 initializers = Bootstrap.new(self).initializers
82b9b15 Refactor plugins
Yehuda Katz + Carl Lerche authored
91 plugins.each { |p| initializers += p.initializers }
8fe66f1 @josh Run railtie and plugin initializers before app specific ones
josh authored
92 initializers += super
82b9b15 Refactor plugins
Yehuda Katz + Carl Lerche authored
93 initializers
94 end
95
d1ffc54 @spastorino fixes the failure of config.plugins without :all option tests [#3718 …
spastorino authored
96 # TODO: Fix this method. It loads all railties independent if :all is given
97 # or not, otherwise frameworks are never loaded.
82b9b15 Refactor plugins
Yehuda Katz + Carl Lerche authored
98 def plugins
99 @plugins ||= begin
bbe80ae @josh config.plugins should still work with an array of strings
josh authored
100 plugin_names = (config.plugins || [:all]).map { |p| p.to_sym }
d1ffc54 @spastorino fixes the failure of config.plugins without :all option tests [#3718 …
spastorino authored
101 Railtie.plugins.map(&:new) + Plugin.all(plugin_names, config.paths.vendor.plugins)
82b9b15 Refactor plugins
Yehuda Katz + Carl Lerche authored
102 end
103 end
104
603d4fb @josh Build middleware stack and reload routes after app initializers run
josh authored
105 def app
106 @app ||= begin
107 reload_routes!
108 middleware.build(routes)
109 end
110 end
111
897164d Conceptually unify instance & global initializers
Yehuda Katz + Carl Lerche authored
112 def call(env)
fc4f237 @josevalim Make filter parameters based on request, so they can be modified for …
josevalim authored
113 env["action_dispatch.parameter_filter"] = config.filter_parameters
603d4fb @josh Build middleware stack and reload routes after app initializers run
josh authored
114 app.call(env)
6d6ae08 Start moving the initializers into the application object
Carl Lerche authored
115 end
116
992c2db Finish porting over the initializers to the app object and fix all th…
Carl Lerche authored
117 initializer :load_application_initializers do
94bb331 @jeremy Shift more responsibility from application class to its singleton ins…
jeremy authored
118 Dir["#{root}/config/initializers/**/*.rb"].sort.each do |initializer|
d0f4d93 Remove some remnants of config.gem
Carl Lerche authored
119 load(initializer)
992c2db Finish porting over the initializers to the app object and fix all th…
Carl Lerche authored
120 end
121 end
122
603d4fb @josh Build middleware stack and reload routes after app initializers run
josh authored
123 initializer :build_middleware_stack do
124 app
125 end
126
992c2db Finish porting over the initializers to the app object and fix all th…
Carl Lerche authored
127 # Fires the user-supplied after_initialize block (Configuration#after_initialize)
128 initializer :after_initialize do
94bb331 @jeremy Shift more responsibility from application class to its singleton ins…
jeremy authored
129 config.after_initialize_blocks.each do |block|
d0f4d93 Remove some remnants of config.gem
Carl Lerche authored
130 block.call
992c2db Finish porting over the initializers to the app object and fix all th…
Carl Lerche authored
131 end
132 end
133
134 # Eager load application classes
135 initializer :load_application_classes do
136 next if $rails_rake_task
137
94bb331 @jeremy Shift more responsibility from application class to its singleton ins…
jeremy authored
138 if config.cache_classes
139 config.eager_load_paths.each do |load_path|
992c2db Finish porting over the initializers to the app object and fix all th…
Carl Lerche authored
140 matcher = /\A#{Regexp.escape(load_path)}(.*)\.rb\Z/
141 Dir.glob("#{load_path}/**/*.rb").sort.each do |file|
142 require_dependency file.sub(matcher, '\1')
143 end
144 end
145 end
146 end
147
148 # Disable dependency loading during request cycle
149 initializer :disable_dependency_loading do
94bb331 @jeremy Shift more responsibility from application class to its singleton ins…
jeremy authored
150 if config.cache_classes && !config.dependency_loading
992c2db Finish porting over the initializers to the app object and fix all th…
Carl Lerche authored
151 ActiveSupport::Dependencies.unhook!
152 end
153 end
accd9b4 @josh Restore "Start Rails::Application object
josh authored
154 end
155 end
Something went wrong with that request. Please try again.