Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 110 lines (91 sloc) 3.299 kb
accd9b4 Joshua Peek Restore "Start Rails::Application object
josh authored
1 module Rails
2 class Application
6d6ae08 Start moving the initializers into the application object
Carl Lerche authored
3 extend Initializable
4
e4d7e50 Moving more initializers into the application object
Carl Lerche authored
5 class << self
6 def config
7 @config ||= Configuration.new
8 end
6f6a589 Create the application object from config/environment.rb
Yehuda Katz + Carl Lerche authored
9
e4d7e50 Moving more initializers into the application object
Carl Lerche authored
10 # TODO: change the plugin loader to use config
11 alias configuration config
c9d4529 Change Rails::Application to a class that is inherited from.
Carl Lerche authored
12
e4d7e50 Moving more initializers into the application object
Carl Lerche authored
13 def config=(config)
14 @config = config
15 end
c9d4529 Change Rails::Application to a class that is inherited from.
Carl Lerche authored
16
e4d7e50 Moving more initializers into the application object
Carl Lerche authored
17 def plugin_loader
18 @plugin_loader ||= config.plugin_loader.new(self)
19 end
accd9b4 Joshua Peek Restore "Start Rails::Application object
josh authored
20
e4d7e50 Moving more initializers into the application object
Carl Lerche authored
21 def routes
22 ActionController::Routing::Routes
23 end
6f6a589 Create the application object from config/environment.rb
Yehuda Katz + Carl Lerche authored
24
e4d7e50 Moving more initializers into the application object
Carl Lerche authored
25 def middleware
26 config.middleware
27 end
28
29 def call(env)
30 @app ||= middleware.build(routes)
31 @app.call(env)
32 end
6d6ae08 Start moving the initializers into the application object
Carl Lerche authored
33
e4d7e50 Moving more initializers into the application object
Carl Lerche authored
34 def new
35 initializers.run
36 self
37 end
6d6ae08 Start moving the initializers into the application object
Carl Lerche authored
38 end
39
40 initializer :initialize_rails do
41 Rails.initializers.run
42 end
43
44 # Set the <tt>$LOAD_PATH</tt> based on the value of
45 # Configuration#load_paths. Duplicates are removed.
46 initializer :set_load_path do
47 config.paths.add_to_load_path
48 $LOAD_PATH.uniq!
49 end
50
51 # Bail if boot.rb is outdated
52 initializer :freak_out_if_boot_rb_is_outdated do
53 unless defined?(Rails::BOOTSTRAP_VERSION)
54 abort %{Your config/boot.rb is outdated: Run "rake rails:update".}
55 end
56 end
e4d7e50 Moving more initializers into the application object
Carl Lerche authored
57
58 # Requires all frameworks specified by the Configuration#frameworks
59 # list. By default, all frameworks (Active Record, Active Support,
60 # Action Pack, Action Mailer, and Active Resource) are loaded.
61 initializer :require_frameworks do
62 begin
63 require 'active_support'
64 require 'active_support/core_ext/kernel/reporting'
65 require 'active_support/core_ext/logger'
66
67 # TODO: This is here to make Sam Ruby's tests pass. Needs discussion.
68 require 'active_support/core_ext/numeric/bytes'
69 config.frameworks.each { |framework| require(framework.to_s) }
70 rescue LoadError => e
71 # Re-raise as RuntimeError because Mongrel would swallow LoadError.
72 raise e.to_s
73 end
74 end
75
76 # Set the paths from which Rails will automatically load source files, and
77 # the load_once paths.
78 initializer :set_autoload_paths do
79 require 'active_support/dependencies'
80 ActiveSupport::Dependencies.load_paths = config.load_paths.uniq
81 ActiveSupport::Dependencies.load_once_paths = config.load_once_paths.uniq
82
83 extra = ActiveSupport::Dependencies.load_once_paths - ActiveSupport::Dependencies.load_paths
84 unless extra.empty?
85 abort <<-end_error
86 load_once_paths must be a subset of the load_paths.
87 Extra items in load_once_paths: #{extra * ','}
88 end_error
89 end
90
91 # Freeze the arrays so future modifications will fail rather than do nothing mysteriously
92 config.load_once_paths.freeze
93 end
94
95 # Adds all load paths from plugins to the global set of load paths, so that
96 # code from plugins can be required (explicitly or automatically via ActiveSupport::Dependencies).
97 initializer :add_plugin_load_paths do
98 require 'active_support/dependencies'
99 plugin_loader.add_plugin_load_paths
100 end
feb04bf Move the ensure_tmp_directories_exist initializer to the application obj...
Carl Lerche authored
101
102 # Create tmp directories
103 initializer :ensure_tmp_directories_exist do
104 %w(cache pids sessions sockets).each do |dir_to_make|
105 FileUtils.mkdir_p(File.join(configuration.root_path, 'tmp', dir_to_make))
106 end
107 end
accd9b4 Joshua Peek Restore "Start Rails::Application object
josh authored
108 end
109 end
Something went wrong with that request. Please try again.