rails 1.2.6 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rails might be problematic. Click here for more details.

Files changed (148) hide show
  1. data/CHANGELOG +491 -12
  2. data/MIT-LICENSE +1 -1
  3. data/README +17 -25
  4. data/Rakefile +41 -18
  5. data/bin/about +1 -1
  6. data/bin/console +1 -1
  7. data/bin/destroy +1 -1
  8. data/bin/generate +1 -1
  9. data/bin/performance/request +3 -0
  10. data/bin/plugin +1 -1
  11. data/bin/runner +1 -1
  12. data/bin/server +1 -1
  13. data/builtin/rails_info/rails/info.rb +2 -2
  14. data/configs/apache.conf +1 -1
  15. data/configs/databases/mysql.yml +9 -3
  16. data/configs/databases/postgresql.yml +16 -12
  17. data/configs/initializers/inflections.rb +10 -0
  18. data/configs/initializers/mime_types.rb +5 -0
  19. data/configs/routes.rb +23 -11
  20. data/doc/README_FOR_APP +1 -1
  21. data/environments/boot.rb +95 -26
  22. data/environments/development.rb +2 -5
  23. data/environments/environment.rb +24 -25
  24. data/environments/test.rb +4 -1
  25. data/helpers/application.rb +5 -2
  26. data/helpers/test_helper.rb +10 -0
  27. data/html/422.html +30 -0
  28. data/html/500.html +1 -1
  29. data/html/index.html +2 -2
  30. data/html/javascripts/controls.js +484 -354
  31. data/html/javascripts/dragdrop.js +88 -58
  32. data/html/javascripts/effects.js +396 -364
  33. data/html/javascripts/prototype.js +2817 -1107
  34. data/html/robots.txt +5 -1
  35. data/lib/commands/console.rb +12 -5
  36. data/lib/commands/performance/request.rb +6 -0
  37. data/lib/commands/plugin.rb +15 -10
  38. data/lib/commands/process/spawner.rb +14 -4
  39. data/lib/commands/servers/base.rb +12 -0
  40. data/lib/commands/servers/mongrel.rb +5 -1
  41. data/lib/commands/servers/webrick.rb +14 -7
  42. data/lib/console_app.rb +5 -2
  43. data/lib/console_with_helpers.rb +5 -2
  44. data/lib/dispatcher.rb +3 -151
  45. data/lib/fcgi_handler.rb +79 -81
  46. data/lib/initializer.rb +125 -169
  47. data/lib/rails/plugin.rb +84 -0
  48. data/lib/rails/plugin/loader.rb +150 -0
  49. data/lib/rails/plugin/locator.rb +78 -0
  50. data/lib/rails/version.rb +3 -3
  51. data/lib/rails_generator/base.rb +11 -9
  52. data/lib/rails_generator/commands.rb +20 -10
  53. data/lib/rails_generator/generators/applications/app/USAGE +0 -7
  54. data/lib/rails_generator/generators/applications/app/app_generator.rb +25 -6
  55. data/lib/rails_generator/generators/components/controller/USAGE +11 -12
  56. data/lib/rails_generator/generators/components/controller/controller_generator.rb +2 -2
  57. data/lib/rails_generator/generators/components/controller/templates/functional_test.rb +1 -11
  58. data/lib/rails_generator/generators/components/controller/templates/{view.rhtml → view.html.erb} +0 -0
  59. data/lib/rails_generator/generators/components/integration_test/USAGE +5 -11
  60. data/lib/rails_generator/generators/components/mailer/USAGE +8 -10
  61. data/lib/rails_generator/generators/components/mailer/mailer_generator.rb +3 -3
  62. data/lib/rails_generator/generators/components/mailer/templates/fixture.erb +3 -0
  63. data/lib/rails_generator/generators/components/mailer/templates/fixture.rhtml +0 -3
  64. data/lib/rails_generator/generators/components/mailer/templates/unit_test.rb +8 -24
  65. data/lib/rails_generator/generators/components/mailer/templates/view.erb +3 -0
  66. data/lib/rails_generator/generators/components/mailer/templates/view.rhtml +0 -3
  67. data/lib/rails_generator/generators/components/migration/USAGE +23 -8
  68. data/lib/rails_generator/generators/components/migration/migration_generator.rb +15 -2
  69. data/lib/rails_generator/generators/components/migration/templates/migration.rb +6 -2
  70. data/lib/rails_generator/generators/components/model/USAGE +15 -14
  71. data/lib/rails_generator/generators/components/model/model_generator.rb +10 -3
  72. data/lib/rails_generator/generators/components/model/templates/fixtures.yml +11 -3
  73. data/lib/rails_generator/generators/components/model/templates/migration.rb +4 -1
  74. data/lib/rails_generator/generators/components/model/templates/unit_test.rb +1 -3
  75. data/lib/rails_generator/generators/components/observer/USAGE +5 -7
  76. data/lib/rails_generator/generators/components/observer/templates/unit_test.rb +0 -2
  77. data/lib/rails_generator/generators/components/plugin/USAGE +8 -18
  78. data/lib/rails_generator/generators/components/plugin/plugin_generator.rb +1 -0
  79. data/lib/rails_generator/generators/components/plugin/templates/MIT-LICENSE +20 -0
  80. data/lib/rails_generator/generators/components/plugin/templates/README +10 -1
  81. data/lib/rails_generator/generators/components/plugin/templates/USAGE +1 -1
  82. data/lib/rails_generator/generators/components/plugin/templates/init.rb +1 -1
  83. data/lib/rails_generator/generators/components/plugin/templates/plugin.rb +1 -1
  84. data/lib/rails_generator/generators/components/plugin/templates/tasks.rake +1 -1
  85. data/lib/rails_generator/generators/components/resource/USAGE +23 -0
  86. data/lib/rails_generator/generators/components/resource/resource_generator.rb +13 -15
  87. data/lib/rails_generator/generators/components/resource/templates/controller.rb +1 -1
  88. data/lib/rails_generator/generators/components/resource/templates/functional_test.rb +2 -14
  89. data/lib/rails_generator/generators/components/scaffold/USAGE +24 -31
  90. data/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +45 -146
  91. data/lib/rails_generator/generators/components/scaffold/templates/controller.rb +64 -37
  92. data/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb +23 -80
  93. data/lib/rails_generator/generators/components/scaffold/templates/{layout.rhtml → layout.html.erb} +0 -0
  94. data/lib/rails_generator/generators/components/scaffold/templates/style.css +1 -1
  95. data/lib/rails_generator/generators/components/{scaffold_resource/templates/view_edit.rhtml → scaffold/templates/view_edit.html.erb} +4 -4
  96. data/lib/rails_generator/generators/components/{scaffold_resource/templates/view_index.rhtml → scaffold/templates/view_index.html.erb} +4 -4
  97. data/lib/rails_generator/generators/components/{scaffold_resource/templates/view_new.rhtml → scaffold/templates/view_new.html.erb} +3 -3
  98. data/lib/rails_generator/generators/components/{scaffold_resource/templates/view_show.rhtml → scaffold/templates/view_show.html.erb} +1 -1
  99. data/lib/rails_generator/generators/components/session_migration/USAGE +6 -11
  100. data/lib/rails_generator/generators/components/session_migration/templates/migration.rb +3 -3
  101. data/lib/rails_generator/lookup.rb +45 -10
  102. data/lib/rails_generator/scripts.rb +6 -3
  103. data/lib/rails_generator/scripts/destroy.rb +23 -0
  104. data/lib/rails_generator/secret_key_generator.rb +160 -0
  105. data/lib/rails_generator/spec.rb +1 -1
  106. data/lib/source_annotation_extractor.rb +62 -0
  107. data/lib/tasks/annotations.rake +23 -0
  108. data/lib/tasks/databases.rake +249 -83
  109. data/lib/tasks/documentation.rake +11 -13
  110. data/lib/tasks/framework.rake +1 -1
  111. data/lib/tasks/rails.rb +1 -1
  112. data/lib/tasks/testing.rake +5 -7
  113. data/lib/test_help.rb +4 -3
  114. data/lib/webrick_server.rb +3 -4
  115. metadata +31 -49
  116. data/bin/breakpointer +0 -3
  117. data/lib/binding_of_caller.rb +0 -85
  118. data/lib/breakpoint.rb +0 -553
  119. data/lib/breakpoint_client.rb +0 -196
  120. data/lib/commands/breakpointer.rb +0 -1
  121. data/lib/rails_generator/generators/components/resource/templates/USAGE +0 -18
  122. data/lib/rails_generator/generators/components/resource/templates/fixtures.yml +0 -11
  123. data/lib/rails_generator/generators/components/resource/templates/migration.rb +0 -13
  124. data/lib/rails_generator/generators/components/resource/templates/model.rb +0 -2
  125. data/lib/rails_generator/generators/components/resource/templates/unit_test.rb +0 -10
  126. data/lib/rails_generator/generators/components/scaffold/templates/form.rhtml +0 -3
  127. data/lib/rails_generator/generators/components/scaffold/templates/form_scaffolding.rhtml +0 -1
  128. data/lib/rails_generator/generators/components/scaffold/templates/view_edit.rhtml +0 -9
  129. data/lib/rails_generator/generators/components/scaffold/templates/view_list.rhtml +0 -27
  130. data/lib/rails_generator/generators/components/scaffold/templates/view_new.rhtml +0 -8
  131. data/lib/rails_generator/generators/components/scaffold/templates/view_show.rhtml +0 -8
  132. data/lib/rails_generator/generators/components/scaffold_resource/USAGE +0 -29
  133. data/lib/rails_generator/generators/components/scaffold_resource/scaffold_resource_generator.rb +0 -93
  134. data/lib/rails_generator/generators/components/scaffold_resource/templates/controller.rb +0 -79
  135. data/lib/rails_generator/generators/components/scaffold_resource/templates/fixtures.yml +0 -11
  136. data/lib/rails_generator/generators/components/scaffold_resource/templates/functional_test.rb +0 -57
  137. data/lib/rails_generator/generators/components/scaffold_resource/templates/helper.rb +0 -2
  138. data/lib/rails_generator/generators/components/scaffold_resource/templates/layout.rhtml +0 -17
  139. data/lib/rails_generator/generators/components/scaffold_resource/templates/migration.rb +0 -13
  140. data/lib/rails_generator/generators/components/scaffold_resource/templates/model.rb +0 -2
  141. data/lib/rails_generator/generators/components/scaffold_resource/templates/style.css +0 -74
  142. data/lib/rails_generator/generators/components/scaffold_resource/templates/unit_test.rb +0 -10
  143. data/lib/rails_generator/generators/components/web_service/USAGE +0 -28
  144. data/lib/rails_generator/generators/components/web_service/templates/api_definition.rb +0 -5
  145. data/lib/rails_generator/generators/components/web_service/templates/controller.rb +0 -8
  146. data/lib/rails_generator/generators/components/web_service/templates/functional_test.rb +0 -19
  147. data/lib/rails_generator/generators/components/web_service/web_service_generator.rb +0 -29
  148. data/lib/tasks/pre_namespace_aliases.rake +0 -53
@@ -9,8 +9,7 @@ class RailsFCGIHandler
9
9
  'INT' => :exit_now,
10
10
  'TERM' => :exit_now,
11
11
  'USR1' => :exit,
12
- 'USR2' => :restart,
13
- 'SIGTRAP' => :breakpoint
12
+ 'USR2' => :restart
14
13
  }
15
14
  GLOBAL_SIGNALS = SIGNALS.keys - %w(USR1)
16
15
 
@@ -42,38 +41,72 @@ class RailsFCGIHandler
42
41
 
43
42
  # Start error timestamp at 11 seconds ago.
44
43
  @last_error_on = Time.now - 11
45
-
46
- dispatcher_log :info, "starting"
47
44
  end
48
45
 
49
46
  def process!(provider = FCGI)
50
- # Make a note of $" so we can safely reload this instance.
51
- mark!
52
-
53
- run_gc! if gc_request_period
47
+ mark_features!
48
+
49
+ dispatcher_log :info, 'starting'
50
+ process_each_request provider
51
+ dispatcher_log :info, 'stopping gracefully'
52
+
53
+ rescue Exception => error
54
+ case error
55
+ when SystemExit
56
+ dispatcher_log :info, 'stopping after explicit exit'
57
+ when SignalException
58
+ dispatcher_error error, 'stopping after unhandled signal'
59
+ else
60
+ # Retry if exceptions occur more than 10 seconds apart.
61
+ if Time.now - @last_error_on > 10
62
+ @last_error_on = Time.now
63
+ dispatcher_error error, 'retrying after unhandled exception'
64
+ retry
65
+ else
66
+ dispatcher_error error, 'stopping after unhandled exception within 10 seconds of the last'
67
+ end
68
+ end
69
+ end
54
70
 
55
- process_each_request!(provider)
56
71
 
57
- GC.enable
58
- dispatcher_log :info, "terminated gracefully"
72
+ protected
73
+ def process_each_request(provider)
74
+ cgi = nil
59
75
 
60
- rescue SystemExit => exit_error
61
- dispatcher_log :info, "terminated by explicit exit"
76
+ provider.each_cgi do |cgi|
77
+ process_request(cgi)
62
78
 
63
- rescue Exception => fcgi_error # FCGI errors
64
- # retry on errors that would otherwise have terminated the FCGI process,
65
- # but only if they occur more than 10 seconds apart.
66
- if !(SignalException === fcgi_error) && Time.now - @last_error_on > 10
67
- @last_error_on = Time.now
68
- dispatcher_error(fcgi_error, "almost killed by this error")
69
- retry
70
- else
71
- dispatcher_error(fcgi_error, "killed by this error")
79
+ case when_ready
80
+ when :reload
81
+ reload!
82
+ when :restart
83
+ close_connection(cgi)
84
+ restart!
85
+ when :exit
86
+ close_connection(cgi)
87
+ break
88
+ end
89
+ end
90
+ rescue SignalException => signal
91
+ raise unless signal.message == 'SIGUSR1'
92
+ close_connection(cgi)
72
93
  end
73
- end
74
94
 
95
+ def process_request(cgi)
96
+ @when_ready = nil
97
+ gc_countdown
98
+
99
+ with_signal_handler 'USR1' do
100
+ begin
101
+ Dispatcher.dispatch(cgi)
102
+ rescue SignalException, SystemExit
103
+ raise
104
+ rescue Exception => error
105
+ dispatcher_error error, 'unhandled dispatch error'
106
+ end
107
+ end
108
+ end
75
109
 
76
- protected
77
110
  def logger
78
111
  @logger ||= Logger.new(@log_file_path)
79
112
  end
@@ -98,10 +131,17 @@ class RailsFCGIHandler
98
131
  end
99
132
 
100
133
  def install_signal_handler(signal, handler = nil)
101
- handler ||= method("#{SIGNALS[signal]}_handler").to_proc
102
- trap(signal, handler)
103
- rescue ArgumentError
104
- dispatcher_log :warn, "Ignoring unsupported signal #{signal}."
134
+ if SIGNALS.include?(signal) && self.class.method_defined?(name = "#{SIGNALS[signal]}_handler")
135
+ handler ||= method(name).to_proc
136
+
137
+ begin
138
+ trap(signal, handler)
139
+ rescue ArgumentError
140
+ dispatcher_log :warn, "Ignoring unsupported signal #{signal}."
141
+ end
142
+ else
143
+ dispatcher_log :warn, "Ignoring unsupported signal #{signal}."
144
+ end
105
145
  end
106
146
 
107
147
  def with_signal_handler(signal)
@@ -112,12 +152,12 @@ class RailsFCGIHandler
112
152
  end
113
153
 
114
154
  def exit_now_handler(signal)
115
- dispatcher_log :info, "asked to terminate immediately"
155
+ dispatcher_log :info, "asked to stop immediately"
116
156
  exit
117
157
  end
118
158
 
119
159
  def exit_handler(signal)
120
- dispatcher_log :info, "asked to terminate ASAP"
160
+ dispatcher_log :info, "asked to stop ASAP"
121
161
  @when_ready = :exit
122
162
  end
123
163
 
@@ -131,46 +171,6 @@ class RailsFCGIHandler
131
171
  @when_ready = :restart
132
172
  end
133
173
 
134
- def breakpoint_handler(signal)
135
- dispatcher_log :info, "asked to breakpoint ASAP"
136
- @when_ready = :breakpoint
137
- end
138
-
139
- def process_each_request!(provider)
140
- cgi = nil
141
- provider.each_cgi do |cgi|
142
- with_signal_handler 'USR1' do
143
- process_request(cgi)
144
- end
145
-
146
- case when_ready
147
- when :reload
148
- reload!
149
- when :restart
150
- close_connection(cgi)
151
- restart!
152
- when :exit
153
- close_connection(cgi)
154
- break
155
- when :breakpoint
156
- close_connection(cgi)
157
- breakpoint!
158
- end
159
-
160
- gc_countdown
161
- end
162
- rescue SignalException => signal
163
- raise unless signal.message == 'SIGUSR1'
164
- close_connection(cgi) if cgi
165
- end
166
-
167
- def process_request(cgi)
168
- Dispatcher.dispatch(cgi)
169
- rescue Exception => e # errors from CGI dispatch
170
- raise if SignalException === e
171
- dispatcher_error(e)
172
- end
173
-
174
174
  def restart!
175
175
  config = ::Config::CONFIG
176
176
  ruby = File::join(config['bindir'], config['ruby_install_name']) + config['EXEEXT']
@@ -178,6 +178,11 @@ class RailsFCGIHandler
178
178
 
179
179
  dispatcher_log :info, "restarted"
180
180
 
181
+ # close resources as they won't be closed by
182
+ # the OS when using exec
183
+ logger.close rescue nil
184
+ RAILS_DEFAULT_LOGGER.close rescue nil
185
+
181
186
  exec(command_line)
182
187
  end
183
188
 
@@ -188,7 +193,8 @@ class RailsFCGIHandler
188
193
  dispatcher_log :info, "reloaded"
189
194
  end
190
195
 
191
- def mark!
196
+ # Make a note of $" so we can safely reload this instance.
197
+ def mark_features!
192
198
  @features = $".clone
193
199
  end
194
200
 
@@ -198,15 +204,6 @@ class RailsFCGIHandler
198
204
  ActionController::Routing::Routes.reload
199
205
  end
200
206
 
201
- def breakpoint!
202
- require 'breakpoint'
203
- port = defined?(BREAKPOINT_SERVER_PORT) ? BREAKPOINT_SERVER_PORT : 42531
204
- Breakpoint.activate_drb("druby://localhost:#{port}", nil, !defined?(FastCGI))
205
- dispatcher_log :info, "breakpointing"
206
- breakpoint
207
- @when_ready = nil
208
- end
209
-
210
207
  def run_gc!
211
208
  @gc_request_countdown = gc_request_period
212
209
  GC.enable; GC.start; GC.disable
@@ -214,12 +211,13 @@ class RailsFCGIHandler
214
211
 
215
212
  def gc_countdown
216
213
  if gc_request_period
214
+ @gc_request_countdown ||= gc_request_period
217
215
  @gc_request_countdown -= 1
218
216
  run_gc! if @gc_request_countdown <= 0
219
217
  end
220
218
  end
221
219
 
222
220
  def close_connection(cgi)
223
- cgi.instance_variable_get("@request").finish
221
+ cgi.instance_variable_get("@request").finish if cgi
224
222
  end
225
223
  end
@@ -5,6 +5,8 @@ require 'pathname'
5
5
  $LOAD_PATH.unshift File.dirname(__FILE__)
6
6
  require 'railties_path'
7
7
  require 'rails/version'
8
+ require 'rails/plugin/locator'
9
+ require 'rails/plugin/loader'
8
10
 
9
11
 
10
12
  RAILS_ENV = (ENV['RAILS_ENV'] || 'development').dup unless defined?(RAILS_ENV)
@@ -21,7 +23,7 @@ module Rails
21
23
  # through the block running:
22
24
  #
23
25
  # Rails::Initializer.run do |config|
24
- # config.frameworks -= [ :action_web_service ]
26
+ # config.frameworks -= [ :action_mailer ]
25
27
  # end
26
28
  #
27
29
  # This will use the default configuration options from Rails::Configuration,
@@ -32,7 +34,7 @@ module Rails
32
34
 
33
35
  # The set of loaded plugins.
34
36
  attr_reader :loaded_plugins
35
-
37
+
36
38
  # Runs the initializer. By default, this will invoke the #process method,
37
39
  # which simply executes all of the initialization routines. Alternately,
38
40
  # you can specify explicitly which initialization routine you want:
@@ -58,34 +60,34 @@ module Rails
58
60
  # Sequentially step through all of the available initialization routines,
59
61
  # in order:
60
62
  #
63
+ # * #check_ruby_version
61
64
  # * #set_load_path
62
- # * #set_connection_adapters
63
65
  # * #require_frameworks
66
+ # * #set_autoload_paths
67
+ # * add_plugin_load_paths
64
68
  # * #load_environment
69
+ # * #initialize_encoding
65
70
  # * #initialize_database
66
71
  # * #initialize_logger
67
72
  # * #initialize_framework_logging
68
73
  # * #initialize_framework_views
69
74
  # * #initialize_dependency_mechanism
70
- # * #initialize_breakpoints
71
75
  # * #initialize_whiny_nils
76
+ # * #initialize_temporary_directories
72
77
  # * #initialize_framework_settings
73
- # * #load_environment
78
+ # * #add_support_load_paths
74
79
  # * #load_plugins
75
80
  # * #load_observers
76
81
  # * #initialize_routing
77
- #
78
- # (Note that #load_environment is invoked twice, once at the start and
79
- # once at the end, to support the legacy configuration style where the
80
- # environment could overwrite the defaults directly, instead of via the
81
- # Configuration instance.
82
+ # * #after_initialize
83
+ # * #load_application_initializers
82
84
  def process
83
85
  check_ruby_version
84
86
  set_load_path
85
- set_connection_adapters
86
-
87
+
87
88
  require_frameworks
88
89
  set_autoload_paths
90
+ add_plugin_load_paths
89
91
  load_environment
90
92
 
91
93
  initialize_encoding
@@ -94,16 +96,10 @@ module Rails
94
96
  initialize_framework_logging
95
97
  initialize_framework_views
96
98
  initialize_dependency_mechanism
97
- initialize_breakpoints
98
99
  initialize_whiny_nils
99
100
  initialize_temporary_directories
100
101
  initialize_framework_settings
101
102
 
102
- # Support for legacy configuration style where the environment
103
- # could overwrite anything set from the defaults/global through
104
- # the individual base class configurations.
105
- load_environment
106
-
107
103
  add_support_load_paths
108
104
 
109
105
  load_plugins
@@ -116,6 +112,8 @@ module Rails
116
112
 
117
113
  # the framework is now fully initialized
118
114
  after_initialize
115
+
116
+ load_application_initializers
119
117
  end
120
118
 
121
119
  # Check for valid Ruby version
@@ -151,58 +149,57 @@ module Rails
151
149
  configuration.load_once_paths.freeze
152
150
  end
153
151
 
154
- # Sets the +RAILS_CONNECTION_ADAPTERS+ constant based on the value of
155
- # Configuration#connection_adapters. This constant is used to determine
156
- # which database adapters should be loaded (by default, all adapters are
157
- # loaded).
158
- def set_connection_adapters
159
- Object.const_set("RAILS_CONNECTION_ADAPTERS", configuration.connection_adapters) if configuration.connection_adapters
160
- end
161
-
162
152
  # Requires all frameworks specified by the Configuration#frameworks
163
153
  # list. By default, all frameworks (ActiveRecord, ActiveSupport,
164
- # ActionPack, ActionMailer, and ActionWebService) are loaded.
154
+ # ActionPack, ActionMailer, and ActiveResource) are loaded.
165
155
  def require_frameworks
166
156
  configuration.frameworks.each { |framework| require(framework.to_s) }
157
+ rescue LoadError => e
158
+ # re-raise because Mongrel would swallow it
159
+ raise e.to_s
167
160
  end
168
161
 
169
162
  # Add the load paths used by support functions such as the info controller
170
163
  def add_support_load_paths
171
164
  end
172
165
 
166
+ # Adds all load paths from plugins to the global set of load paths, so that
167
+ # code from plugins can be required (explicitly or automatically via Dependencies).
168
+ def add_plugin_load_paths
169
+ plugin_loader.add_plugin_load_paths
170
+ end
171
+
173
172
  # Loads all plugins in <tt>config.plugin_paths</tt>. <tt>plugin_paths</tt>
174
173
  # defaults to <tt>vendor/plugins</tt> but may also be set to a list of
175
174
  # paths, such as
176
- # config.plugin_paths = ['lib/plugins', 'vendor/plugins']
175
+ # config.plugin_paths = ["#{RAILS_ROOT}/lib/plugins", "#{RAILS_ROOT}/vendor/plugins"]
177
176
  #
178
- # Each plugin discovered in <tt>plugin_paths</tt> is initialized:
179
- # * add its +lib+ directory, if present, to the beginning of the load path
180
- # * evaluate <tt>init.rb</tt> if present
177
+ # In the default implementation, as each plugin discovered in <tt>plugin_paths</tt> is initialized:
178
+ # * its +lib+ directory, if present, is added to the load path (immediately after the applications lib directory)
179
+ # * <tt>init.rb</tt> is evaluated, if present
181
180
  #
182
181
  # After all plugins are loaded, duplicates are removed from the load path.
183
- # If an array of plugin names is specified in config.plugins, the plugins
184
- # will be loaded in that order. Otherwise, plugins are loaded in alphabetical
182
+ # If an array of plugin names is specified in config.plugins, only those plugins will be loaded
183
+ # and they plugins will be loaded in that order. Otherwise, plugins are loaded in alphabetical
185
184
  # order.
185
+ #
186
+ # if config.plugins ends contains :all then the named plugins will be loaded in the given order and all other
187
+ # plugins will be loaded in alphabetical order
186
188
  def load_plugins
187
- if configuration.plugins.nil?
188
- # a nil value implies we don't care about plugins; load 'em all in a reliable order
189
- find_plugins(configuration.plugin_paths).sort.each { |path| load_plugin path }
190
- elsif !configuration.plugins.empty?
191
- # we've specified a config.plugins array, so respect that order
192
- plugin_paths = find_plugins(configuration.plugin_paths)
193
- configuration.plugins.each do |name|
194
- path = plugin_paths.find { |p| File.basename(p) == name }
195
- raise(LoadError, "Cannot find the plugin '#{name}'!") if path.nil?
196
- load_plugin path
197
- end
198
- end
199
- $LOAD_PATH.uniq!
189
+ plugin_loader.load_plugins
190
+ end
191
+
192
+ def plugin_loader
193
+ @plugin_loader ||= configuration.plugin_loader.new(self)
200
194
  end
201
195
 
202
196
  # Loads the environment specified by Configuration#environment_path, which
203
- # is typically one of development, testing, or production.
197
+ # is typically one of development, test, or production.
204
198
  def load_environment
205
199
  silence_warnings do
200
+ return if @environment_loaded
201
+ @environment_loaded = true
202
+
206
203
  config = configuration
207
204
  constants = self.class.constants
208
205
 
@@ -215,10 +212,12 @@ module Rails
215
212
  end
216
213
 
217
214
  def load_observers
218
- ActiveRecord::Base.instantiate_observers
215
+ if configuration.frameworks.include?(:active_record)
216
+ ActiveRecord::Base.instantiate_observers
217
+ end
219
218
  end
220
219
 
221
- # This initialzation sets $KCODE to 'u' to enable the multibyte safe operations.
220
+ # This initialization sets $KCODE to 'u' to enable the multibyte safe operations.
222
221
  # Plugin authors supporting other encodings should override this behaviour and
223
222
  # set the relevant +default_charset+ on ActionController::Base
224
223
  def initialize_encoding
@@ -230,9 +229,10 @@ module Rails
230
229
  # this sets the database configuration from Configuration#database_configuration
231
230
  # and then establishes the connection.
232
231
  def initialize_database
233
- return unless configuration.frameworks.include?(:active_record)
234
- ActiveRecord::Base.configurations = configuration.database_configuration
235
- ActiveRecord::Base.establish_connection
232
+ if configuration.frameworks.include?(:active_record)
233
+ ActiveRecord::Base.configurations = configuration.database_configuration
234
+ ActiveRecord::Base.establish_connection
235
+ end
236
236
  end
237
237
 
238
238
  # If the +RAILS_DEFAULT_LOGGER+ constant is already set, this initialization
@@ -249,11 +249,12 @@ module Rails
249
249
 
250
250
  unless logger = configuration.logger
251
251
  begin
252
- logger = Logger.new(configuration.log_path)
253
- logger.level = Logger.const_get(configuration.log_level.to_s.upcase)
254
- rescue StandardError
255
- logger = Logger.new(STDERR)
256
- logger.level = Logger::WARN
252
+ logger = ActiveSupport::BufferedLogger.new(configuration.log_path)
253
+ logger.level = ActiveSupport::BufferedLogger.const_get(configuration.log_level.to_s.upcase)
254
+ logger.auto_flushing = false if configuration.environment == "production"
255
+ rescue StandardError =>e
256
+ logger = ActiveSupport::BufferedLogger.new(STDERR)
257
+ logger.level = ActiveSupport::BufferedLogger::WARN
257
258
  logger.warn(
258
259
  "Rails Error: Unable to access log file. Please ensure that #{configuration.log_path} exists and is chmod 0666. " +
259
260
  "The log level has been raised to WARN and the output directed to STDERR until the problem is fixed."
@@ -274,14 +275,13 @@ module Rails
274
275
  end
275
276
  end
276
277
 
277
- # Sets the +template_root+ for ActionController::Base and ActionMailer::Base
278
+ # Sets +ActionController::Base#view_paths+ and +ActionMailer::Base#template_root+
278
279
  # (but only for those frameworks that are to be loaded). If the framework's
279
- # +template_root+ has already been set, it is not changed, otherwise it is
280
+ # paths have already been set, it is not changed, otherwise it is
280
281
  # set to use Configuration#view_path.
281
282
  def initialize_framework_views
282
- for framework in ([ :action_controller, :action_mailer ] & configuration.frameworks)
283
- framework.to_s.camelize.constantize.const_get("Base").template_root ||= configuration.view_path
284
- end
283
+ ActionMailer::Base.template_root ||= configuration.view_path if configuration.frameworks.include?(:action_mailer)
284
+ ActionController::Base.view_paths = [configuration.view_path] if configuration.frameworks.include?(:action_controller) && ActionController::Base.view_paths.empty?
285
285
  end
286
286
 
287
287
  # If ActionController is not one of the loaded frameworks (Configuration#frameworks)
@@ -299,12 +299,6 @@ module Rails
299
299
  Dependencies.mechanism = configuration.cache_classes ? :require : :load
300
300
  end
301
301
 
302
- # Sets the +BREAKPOINT_SERVER_PORT+ if Configuration#breakpoint_server
303
- # is true.
304
- def initialize_breakpoints
305
- silence_warnings { Object.const_set("BREAKPOINT_SERVER_PORT", 42531) if configuration.breakpoint_server }
306
- end
307
-
308
302
  # Loads support for "whiny nil" (noisy warnings when methods are invoked
309
303
  # on +nil+ values) if Configuration#whiny_nils is true.
310
304
  def initialize_whiny_nils
@@ -338,76 +332,17 @@ module Rails
338
332
 
339
333
  # Fires the user-supplied after_initialize block (Configuration#after_initialize)
340
334
  def after_initialize
341
- configuration.after_initialize_block.call if configuration.after_initialize_block
342
- end
343
-
344
- protected
345
- # Return a list of plugin paths within base_path. A plugin path is
346
- # a directory that contains either a lib directory or an init.rb file.
347
- # This recurses into directories which are not plugin paths, so you
348
- # may organize your plugins within the plugin path.
349
- def find_plugins(*base_paths)
350
- base_paths.flatten.inject([]) do |plugins, base_path|
351
- Dir.glob(File.join(base_path, '*')).each do |path|
352
- if plugin_path?(path)
353
- plugins << path if plugin_enabled?(path)
354
- elsif File.directory?(path)
355
- plugins += find_plugins(path)
356
- end
357
- end
358
- plugins
359
- end
360
- end
361
-
362
- def plugin_path?(path)
363
- File.directory?(path) and (File.directory?(File.join(path, 'lib')) or File.file?(File.join(path, 'init.rb')))
335
+ configuration.after_initialize_blocks.each do |block|
336
+ block.call
364
337
  end
338
+ end
365
339
 
366
- def plugin_enabled?(path)
367
- configuration.plugins.nil? || configuration.plugins.include?(File.basename(path))
340
+ def load_application_initializers
341
+ Dir["#{configuration.root_path}/config/initializers/**/*.rb"].sort.each do |initializer|
342
+ load(initializer)
368
343
  end
344
+ end
369
345
 
370
- # Load the plugin at <tt>path</tt> unless already loaded.
371
- #
372
- # Each plugin is initialized:
373
- # * add its +lib+ directory, if present, to the beginning of the load path
374
- # * evaluate <tt>init.rb</tt> if present
375
- #
376
- # Returns <tt>true</tt> if the plugin is successfully loaded or
377
- # <tt>false</tt> if it is already loaded (similar to Kernel#require).
378
- # Raises <tt>LoadError</tt> if the plugin is not found.
379
- def load_plugin(directory)
380
- name = File.basename(directory)
381
- return false if loaded_plugins.include?(name)
382
-
383
- # Catch nonexistent and empty plugins.
384
- raise LoadError, "No such plugin: #{directory}" unless plugin_path?(directory)
385
-
386
- lib_path = File.join(directory, 'lib')
387
- init_path = File.join(directory, 'init.rb')
388
- has_lib = File.directory?(lib_path)
389
- has_init = File.file?(init_path)
390
-
391
- # Add lib to load path *after* the application lib, to allow
392
- # application libraries to override plugin libraries.
393
- if has_lib
394
- application_lib_index = $LOAD_PATH.index(File.join(RAILS_ROOT, "lib")) || 0
395
- $LOAD_PATH.insert(application_lib_index + 1, lib_path)
396
- Dependencies.load_paths << lib_path
397
- Dependencies.load_once_paths << lib_path
398
- end
399
-
400
- # Allow plugins to reference the current configuration object
401
- config = configuration
402
-
403
- # Add to set of loaded plugins before 'name' collapsed in eval.
404
- loaded_plugins << name
405
-
406
- # Evaluate init.rb.
407
- silence_warnings { eval(IO.read(init_path), binding, init_path) } if has_init
408
-
409
- true
410
- end
411
346
  end
412
347
 
413
348
  # The Configuration class holds all the parameters for the Initializer and
@@ -432,24 +367,16 @@ module Rails
432
367
  # A stub for setting options on ActionView::Base
433
368
  attr_accessor :action_view
434
369
 
435
- # A stub for setting options on ActionWebService::Base
436
- attr_accessor :action_web_service
437
-
438
370
  # A stub for setting options on ActiveRecord::Base
439
371
  attr_accessor :active_record
440
372
 
441
- # Whether or not to use the breakpoint server (boolean)
442
- attr_accessor :breakpoint_server
373
+ # A stub for setting options on ActiveRecord::Base
374
+ attr_accessor :active_resource
443
375
 
444
376
  # Whether or not classes should be cached (set to false if you want
445
377
  # application classes to be reloaded on each request)
446
378
  attr_accessor :cache_classes
447
379
 
448
- # The list of connection adapters to load. (By default, all connection
449
- # adapters are loaded. You can set this to be just the adapter(s) you
450
- # will use to reduce your application's load time.)
451
- attr_accessor :connection_adapters
452
-
453
380
  # The list of paths that should be searched for controllers. (Defaults
454
381
  # to <tt>app/controllers</tt> and <tt>components</tt>.)
455
382
  attr_accessor :controller_paths
@@ -461,7 +388,7 @@ module Rails
461
388
  # The list of rails framework components that should be loaded. (Defaults
462
389
  # to <tt>:active_record</tt>, <tt>:action_controller</tt>,
463
390
  # <tt>:action_view</tt>, <tt>:action_mailer</tt>, and
464
- # <tt>:action_web_service</tt>).
391
+ # <tt>:active_resource</tt>).
465
392
  attr_accessor :frameworks
466
393
 
467
394
  # An array of additional paths to prepend to the load path. By default,
@@ -497,12 +424,36 @@ module Rails
497
424
  # The list of plugins to load. If this is set to <tt>nil</tt>, all plugins will
498
425
  # be loaded. If this is set to <tt>[]</tt>, no plugins will be loaded. Otherwise,
499
426
  # plugins will be loaded in the order specified.
500
- attr_accessor :plugins
427
+ attr_reader :plugins
428
+ def plugins=(plugins)
429
+ @plugins = plugins.nil? ? nil : plugins.map { |p| p.to_sym }
430
+ end
501
431
 
502
432
  # The path to the root of the plugins directory. By default, it is in
503
433
  # <tt>vendor/plugins</tt>.
504
434
  attr_accessor :plugin_paths
505
435
 
436
+ # The classes that handle finding the desired plugins that you'd like to load for
437
+ # your application. By default it is the Rails::Plugin::FileSystemLocator which finds
438
+ # plugins to load in <tt>vendor/plugins</tt>. You can hook into gem location by subclassing
439
+ # Rails::Plugin::Locator and adding it onto the list of <tt>plugin_locators</tt>.
440
+ attr_accessor :plugin_locators
441
+
442
+ # The class that handles loading each plugin. Defaults to Rails::Plugin::Loader, but
443
+ # a sub class would have access to fine grained modification of the loading behavior. See
444
+ # the implementation of Rails::Plugin::Loader for more details.
445
+ attr_accessor :plugin_loader
446
+
447
+ # Deprecated options:
448
+ def breakpoint_server(_ = nil)
449
+ $stderr.puts %(
450
+ *******************************************************************
451
+ * config.breakpoint_server has been deprecated and has no effect. *
452
+ *******************************************************************
453
+ )
454
+ end
455
+ alias_method :breakpoint_server=, :breakpoint_server
456
+
506
457
  # Create a new Configuration instance, initialized with the default
507
458
  # values.
508
459
  def initialize
@@ -516,10 +467,11 @@ module Rails
516
467
  self.view_path = default_view_path
517
468
  self.controller_paths = default_controller_paths
518
469
  self.cache_classes = default_cache_classes
519
- self.breakpoint_server = default_breakpoint_server
520
470
  self.whiny_nils = default_whiny_nils
521
471
  self.plugins = default_plugins
522
472
  self.plugin_paths = default_plugin_paths
473
+ self.plugin_locators = default_plugin_locators
474
+ self.plugin_loader = default_plugin_loader
523
475
  self.database_configuration_file = default_database_configuration_file
524
476
 
525
477
  for framework in default_frameworks
@@ -542,6 +494,9 @@ module Rails
542
494
  else
543
495
  Pathname.new(::RAILS_ROOT).realpath.to_s
544
496
  end
497
+
498
+ Object.const_set(:RELATIVE_RAILS_ROOT, ::RAILS_ROOT.dup) unless defined?(::RELATIVE_RAILS_ROOT)
499
+ ::RAILS_ROOT.replace @root_path
545
500
  end
546
501
 
547
502
  # Loads and returns the contents of the #database_configuration_file. The
@@ -563,16 +518,16 @@ module Rails
563
518
  ::RAILS_ENV
564
519
  end
565
520
 
566
- # Sets a block which will be executed after rails has been fully initialized.
521
+ # Adds a block which will be executed after rails has been fully initialized.
567
522
  # Useful for per-environment configuration which depends on the framework being
568
523
  # fully initialized.
569
524
  def after_initialize(&after_initialize_block)
570
- @after_initialize_block = after_initialize_block
525
+ after_initialize_blocks << after_initialize_block if after_initialize_block
571
526
  end
572
527
 
573
- # Returns the block set in Configuration#after_initialize
574
- def after_initialize_block
575
- @after_initialize_block
528
+ # Returns the blocks added with Configuration#after_initialize
529
+ def after_initialize_blocks
530
+ @after_initialize_blocks ||= []
576
531
  end
577
532
 
578
533
  # Add a preparation callback that will run before every request in development
@@ -590,16 +545,14 @@ module Rails
590
545
  end
591
546
 
592
547
  def framework_paths
593
- # TODO: Don't include dirs for frameworks that are not used
594
- %w(
595
- railties
596
- railties/lib
597
- actionpack/lib
598
- activesupport/lib
599
- activerecord/lib
600
- actionmailer/lib
601
- actionwebservice/lib
602
- ).map { |dir| "#{framework_root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
548
+ paths = %w(railties railties/lib activesupport/lib)
549
+ paths << 'actionpack/lib' if frameworks.include? :action_controller or frameworks.include? :action_view
550
+
551
+ [:active_record, :action_mailer, :active_resource, :action_web_service].each do |framework|
552
+ paths << "#{framework.to_s.gsub('_', '')}/lib" if frameworks.include? framework
553
+ end
554
+
555
+ paths.map { |dir| "#{framework_root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
603
556
  end
604
557
 
605
558
  private
@@ -608,7 +561,7 @@ module Rails
608
561
  end
609
562
 
610
563
  def default_frameworks
611
- [ :active_record, :action_controller, :action_view, :action_mailer, :action_web_service ]
564
+ [ :active_record, :action_controller, :action_view, :action_mailer, :active_resource ]
612
565
  end
613
566
 
614
567
  def default_load_paths
@@ -627,7 +580,6 @@ module Rails
627
580
  app/controllers
628
581
  app/helpers
629
582
  app/services
630
- app/apis
631
583
  components
632
584
  config
633
585
  lib
@@ -659,7 +611,7 @@ module Rails
659
611
  end
660
612
 
661
613
  def default_controller_paths
662
- paths = [ File.join(root_path, 'app', 'controllers'), File.join(root_path, 'components') ]
614
+ paths = [File.join(root_path, 'app', 'controllers')]
663
615
  paths.concat builtin_directories
664
616
  paths
665
617
  end
@@ -672,10 +624,6 @@ module Rails
672
624
  false
673
625
  end
674
626
 
675
- def default_breakpoint_server
676
- false
677
- end
678
-
679
627
  def default_whiny_nils
680
628
  false
681
629
  end
@@ -687,6 +635,14 @@ module Rails
687
635
  def default_plugin_paths
688
636
  ["#{root_path}/vendor/plugins"]
689
637
  end
638
+
639
+ def default_plugin_locators
640
+ [Plugin::FileSystemLocator]
641
+ end
642
+
643
+ def default_plugin_loader
644
+ Plugin::Loader
645
+ end
690
646
  end
691
647
  end
692
648