Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 152 lines (124 sloc) 3.701 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
106d8f7 AppName::Application.root should work
Yehuda Katz authored
11 delegate :initialize!, :load_tasks, :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
82b9b15 Refactor plugins
Yehuda Katz + Carl Lerche authored
85 def initializers
8fe66f1 @josh Run railtie and plugin initializers before app specific ones
josh authored
86 initializers = Bootstrap.new(self).initializers
82b9b15 Refactor plugins
Yehuda Katz + Carl Lerche authored
87 plugins.each { |p| initializers += p.initializers }
8fe66f1 @josh Run railtie and plugin initializers before app specific ones
josh authored
88 initializers += super
82b9b15 Refactor plugins
Yehuda Katz + Carl Lerche authored
89 initializers
90 end
91
38aeb15 Moving out some framework specific initializers into the framework li…
Carlhuda authored
92 # TODO: Fix this method
82b9b15 Refactor plugins
Yehuda Katz + Carl Lerche authored
93 def plugins
94 @plugins ||= begin
bbe80ae @josh config.plugins should still work with an array of strings
josh authored
95 plugin_names = (config.plugins || [:all]).map { |p| p.to_sym }
96 Railtie.plugins.select { |p|
97 plugin_names.include?(:all) || plugin_names.include?(p.plugin_name)
98 }.map { |p| p.new } + Plugin.all(plugin_names, config.paths.vendor.plugins)
82b9b15 Refactor plugins
Yehuda Katz + Carl Lerche authored
99 end
100 end
101
603d4fb @josh Build middleware stack and reload routes after app initializers run
josh authored
102 def app
103 @app ||= begin
104 reload_routes!
105 middleware.build(routes)
106 end
107 end
108
897164d Conceptually unify instance & global initializers
Yehuda Katz + Carl Lerche authored
109 def call(env)
603d4fb @josh Build middleware stack and reload routes after app initializers run
josh authored
110 app.call(env)
6d6ae08 Start moving the initializers into the application object
Carl Lerche authored
111 end
112
992c2db Finish porting over the initializers to the app object and fix all th…
Carl Lerche authored
113 initializer :load_application_initializers do
94bb331 @jeremy Shift more responsibility from application class to its singleton ins…
jeremy authored
114 Dir["#{root}/config/initializers/**/*.rb"].sort.each do |initializer|
d0f4d93 Remove some remnants of config.gem
Carl Lerche authored
115 load(initializer)
992c2db Finish porting over the initializers to the app object and fix all th…
Carl Lerche authored
116 end
117 end
118
603d4fb @josh Build middleware stack and reload routes after app initializers run
josh authored
119 initializer :build_middleware_stack do
120 app
121 end
122
992c2db Finish porting over the initializers to the app object and fix all th…
Carl Lerche authored
123 # Fires the user-supplied after_initialize block (Configuration#after_initialize)
124 initializer :after_initialize do
94bb331 @jeremy Shift more responsibility from application class to its singleton ins…
jeremy authored
125 config.after_initialize_blocks.each do |block|
d0f4d93 Remove some remnants of config.gem
Carl Lerche authored
126 block.call
992c2db Finish porting over the initializers to the app object and fix all th…
Carl Lerche authored
127 end
128 end
129
130 # Eager load application classes
131 initializer :load_application_classes do
132 next if $rails_rake_task
133
94bb331 @jeremy Shift more responsibility from application class to its singleton ins…
jeremy authored
134 if config.cache_classes
135 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
136 matcher = /\A#{Regexp.escape(load_path)}(.*)\.rb\Z/
137 Dir.glob("#{load_path}/**/*.rb").sort.each do |file|
138 require_dependency file.sub(matcher, '\1')
139 end
140 end
141 end
142 end
143
144 # Disable dependency loading during request cycle
145 initializer :disable_dependency_loading do
94bb331 @jeremy Shift more responsibility from application class to its singleton ins…
jeremy authored
146 if config.cache_classes && !config.dependency_loading
992c2db Finish porting over the initializers to the app object and fix all th…
Carl Lerche authored
147 ActiveSupport::Dependencies.unhook!
148 end
149 end
accd9b4 @josh Restore "Start Rails::Application object
josh authored
150 end
151 end
Something went wrong with that request. Please try again.