railties 3.0.0.beta → 3.0.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (232) hide show
  1. data/CHANGELOG +15 -1
  2. data/README +9 -9
  3. data/bin/rails +28 -9
  4. data/guides/images/challenge.png +0 -0
  5. data/guides/images/edge_badge.png +0 -0
  6. data/guides/images/posts_index.png +0 -0
  7. data/guides/images/rails_welcome.png +0 -0
  8. data/guides/rails_guides.rb +9 -22
  9. data/guides/rails_guides/generator.rb +79 -50
  10. data/guides/rails_guides/textile_extensions.rb +3 -3
  11. data/guides/source/2_2_release_notes.textile +1 -1
  12. data/guides/source/2_3_release_notes.textile +1 -1
  13. data/guides/source/3_0_release_notes.textile +46 -38
  14. data/guides/source/action_controller_overview.textile +2 -2
  15. data/guides/source/action_mailer_basics.textile +4 -4
  16. data/guides/source/action_view_overview.textile +2 -2
  17. data/guides/source/active_record_querying.textile +73 -95
  18. data/guides/source/active_support_core_extensions.textile +993 -85
  19. data/guides/source/activerecord_validations_callbacks.textile +3 -3
  20. data/guides/source/caching_with_rails.textile +1 -1
  21. data/guides/source/command_line.textile +90 -88
  22. data/guides/source/configuring.textile +10 -10
  23. data/guides/source/contribute.textile +2 -2
  24. data/guides/source/contributing_to_rails.textile +14 -7
  25. data/guides/source/credits.textile.erb +8 -0
  26. data/guides/source/debugging_rails_applications.textile +6 -6
  27. data/guides/source/form_helpers.textile +1 -1
  28. data/guides/source/generators.textile +14 -14
  29. data/guides/source/getting_started.textile +634 -500
  30. data/guides/source/index.textile.erb +16 -1
  31. data/guides/source/layout.html.erb +7 -1
  32. data/guides/source/layouts_and_rendering.textile +299 -71
  33. data/guides/source/migrations.textile +5 -5
  34. data/guides/source/performance_testing.textile +8 -8
  35. data/guides/source/plugins.textile +26 -24
  36. data/guides/source/rails_on_rack.textile +5 -5
  37. data/guides/source/routing.textile +119 -117
  38. data/guides/source/security.textile +1 -1
  39. data/guides/source/testing.textile +4 -4
  40. data/lib/rails.rb +4 -1
  41. data/lib/rails/application.rb +44 -7
  42. data/lib/rails/application/bootstrap.rb +2 -14
  43. data/lib/rails/application/configuration.rb +69 -5
  44. data/lib/rails/application/finisher.rb +2 -3
  45. data/lib/rails/application/metal_loader.rb +1 -1
  46. data/lib/rails/application/routes_reloader.rb +1 -1
  47. data/lib/rails/backtrace_cleaner.rb +0 -11
  48. data/lib/rails/commands.rb +7 -6
  49. data/lib/rails/commands/application.rb +1 -1
  50. data/lib/rails/commands/console.rb +1 -1
  51. data/lib/rails/commands/dbconsole.rb +12 -0
  52. data/lib/rails/commands/destroy.rb +2 -2
  53. data/lib/rails/commands/generate.rb +2 -2
  54. data/lib/rails/commands/performance/benchmarker.rb +2 -2
  55. data/lib/rails/commands/performance/profiler.rb +2 -2
  56. data/lib/rails/commands/plugin.rb +6 -6
  57. data/lib/rails/commands/runner.rb +2 -0
  58. data/lib/rails/commands/server.rb +23 -8
  59. data/lib/rails/configuration.rb +2 -84
  60. data/lib/rails/console/app.rb +4 -3
  61. data/lib/rails/console/helpers.rb +3 -1
  62. data/lib/rails/engine.rb +107 -12
  63. data/lib/rails/engine/configuration.rb +8 -2
  64. data/lib/rails/generators.rb +22 -7
  65. data/lib/rails/generators/actions.rb +16 -6
  66. data/lib/rails/generators/base.rb +15 -8
  67. data/lib/rails/generators/erb.rb +21 -0
  68. data/lib/{generators → rails/generators}/erb/controller/controller_generator.rb +4 -5
  69. data/lib/{generators → rails/generators}/erb/controller/templates/view.html.erb +0 -0
  70. data/lib/rails/generators/erb/mailer/mailer_generator.rb +13 -0
  71. data/lib/{generators → rails/generators}/erb/mailer/templates/view.text.erb +0 -0
  72. data/lib/{generators → rails/generators}/erb/scaffold/scaffold_generator.rb +14 -26
  73. data/lib/{generators → rails/generators}/erb/scaffold/templates/_form.html.erb +1 -1
  74. data/lib/{generators → rails/generators}/erb/scaffold/templates/edit.html.erb +0 -0
  75. data/lib/{generators → rails/generators}/erb/scaffold/templates/index.html.erb +1 -1
  76. data/lib/{generators → rails/generators}/erb/scaffold/templates/layout.html.erb +1 -0
  77. data/lib/{generators → rails/generators}/erb/scaffold/templates/new.html.erb +0 -0
  78. data/lib/{generators → rails/generators}/erb/scaffold/templates/show.html.erb +0 -0
  79. data/lib/rails/generators/named_base.rb +4 -0
  80. data/lib/{generators → rails/generators}/rails/app/USAGE +0 -0
  81. data/lib/{generators → rails/generators}/rails/app/app_generator.rb +21 -7
  82. data/lib/rails/generators/rails/app/templates/Gemfile +34 -0
  83. data/lib/{generators → rails/generators}/rails/app/templates/README +9 -8
  84. data/lib/{generators → rails/generators}/rails/app/templates/Rakefile +0 -0
  85. data/lib/{generators → rails/generators}/rails/app/templates/app/controllers/application_controller.rb +0 -0
  86. data/lib/{generators → rails/generators}/rails/app/templates/app/helpers/application_helper.rb +0 -0
  87. data/lib/{generators → rails/generators}/rails/app/templates/app/models/.empty_directory +0 -0
  88. data/lib/{generators → rails/generators}/rails/app/templates/app/views/layouts/.empty_directory +0 -0
  89. data/lib/{generators → rails/generators}/rails/app/templates/config.ru +0 -0
  90. data/lib/{generators → rails/generators}/rails/app/templates/config/application.rb +4 -3
  91. data/lib/rails/generators/rails/app/templates/config/boot.rb +14 -0
  92. data/lib/{generators → rails/generators}/rails/app/templates/config/databases/frontbase.yml +0 -0
  93. data/lib/{generators → rails/generators}/rails/app/templates/config/databases/ibm_db.yml +0 -0
  94. data/lib/{generators → rails/generators}/rails/app/templates/config/databases/mysql.yml +0 -0
  95. data/lib/{generators → rails/generators}/rails/app/templates/config/databases/oracle.yml +0 -0
  96. data/lib/{generators → rails/generators}/rails/app/templates/config/databases/postgresql.yml +0 -0
  97. data/lib/{generators → rails/generators}/rails/app/templates/config/databases/sqlite3.yml +0 -0
  98. data/lib/{generators → rails/generators}/rails/app/templates/config/environment.rb +0 -0
  99. data/lib/{generators → rails/generators}/rails/app/templates/config/environments/development.rb.tt +0 -0
  100. data/lib/{generators → rails/generators}/rails/app/templates/config/environments/production.rb.tt +9 -0
  101. data/lib/{generators → rails/generators}/rails/app/templates/config/environments/test.rb.tt +0 -0
  102. data/lib/{generators → rails/generators}/rails/app/templates/config/initializers/backtrace_silencers.rb +0 -0
  103. data/lib/{generators → rails/generators}/rails/app/templates/config/initializers/cookie_verification_secret.rb.tt +1 -1
  104. data/lib/{generators → rails/generators}/rails/app/templates/config/initializers/inflections.rb +0 -0
  105. data/lib/{generators → rails/generators}/rails/app/templates/config/initializers/mime_types.rb +0 -0
  106. data/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +10 -0
  107. data/lib/{generators → rails/generators}/rails/app/templates/config/locales/en.yml +0 -0
  108. data/lib/{generators → rails/generators}/rails/app/templates/config/routes.rb +0 -0
  109. data/lib/{generators → rails/generators}/rails/app/templates/db/seeds.rb +0 -0
  110. data/lib/{generators → rails/generators}/rails/app/templates/doc/README_FOR_APP +0 -0
  111. data/lib/{generators → rails/generators}/rails/app/templates/gitignore +0 -0
  112. data/lib/{generators → rails/generators}/rails/app/templates/public/404.html +0 -0
  113. data/lib/{generators → rails/generators}/rails/app/templates/public/422.html +0 -0
  114. data/lib/{generators → rails/generators}/rails/app/templates/public/500.html +0 -0
  115. data/lib/{generators → rails/generators}/rails/app/templates/public/favicon.ico +0 -0
  116. data/lib/{generators → rails/generators}/rails/app/templates/public/images/rails.png +0 -0
  117. data/lib/{generators → rails/generators}/rails/app/templates/public/index.html +17 -17
  118. data/lib/{generators → rails/generators}/rails/app/templates/public/javascripts/application.js +0 -0
  119. data/lib/{generators → rails/generators}/rails/app/templates/public/javascripts/controls.js +5 -3
  120. data/lib/{generators → rails/generators}/rails/app/templates/public/javascripts/dragdrop.js +7 -6
  121. data/lib/{generators → rails/generators}/rails/app/templates/public/javascripts/effects.js +8 -13
  122. data/lib/{generators → rails/generators}/rails/app/templates/public/javascripts/prototype.js +1573 -1019
  123. data/lib/{generators → rails/generators}/rails/app/templates/public/javascripts/rails.js +1 -2
  124. data/lib/{generators → rails/generators}/rails/app/templates/public/robots.txt +0 -0
  125. data/lib/{generators → rails/generators}/rails/app/templates/public/stylesheets/.empty_directory +0 -0
  126. data/lib/{generators → rails/generators}/rails/app/templates/script/rails +0 -1
  127. data/lib/{generators → rails/generators}/rails/app/templates/test/fixtures/.empty_directory +0 -0
  128. data/lib/{generators → rails/generators}/rails/app/templates/test/functional/.empty_directory +0 -0
  129. data/lib/{generators → rails/generators}/rails/app/templates/test/integration/.empty_directory +0 -0
  130. data/lib/{generators → rails/generators}/rails/app/templates/test/performance/browsing_test.rb +1 -1
  131. data/lib/{generators → rails/generators}/rails/app/templates/test/test_helper.rb +1 -1
  132. data/lib/{generators → rails/generators}/rails/app/templates/test/unit/.empty_directory +0 -0
  133. data/lib/{generators → rails/generators}/rails/controller/USAGE +1 -1
  134. data/lib/{generators → rails/generators}/rails/controller/controller_generator.rb +6 -0
  135. data/lib/{generators → rails/generators}/rails/controller/templates/controller.rb +0 -0
  136. data/lib/{generators → rails/generators}/rails/generator/USAGE +1 -1
  137. data/lib/{generators → rails/generators}/rails/generator/generator_generator.rb +0 -0
  138. data/lib/{generators → rails/generators}/rails/generator/templates/%file_name%_generator.rb.tt +0 -0
  139. data/lib/{generators → rails/generators}/rails/generator/templates/USAGE.tt +1 -1
  140. data/lib/{generators → rails/generators}/rails/generator/templates/templates/.empty_directory +0 -0
  141. data/lib/{generators → rails/generators}/rails/helper/USAGE +1 -1
  142. data/lib/{generators → rails/generators}/rails/helper/helper_generator.rb +0 -0
  143. data/lib/{generators → rails/generators}/rails/helper/templates/helper.rb +0 -0
  144. data/lib/{generators → rails/generators}/rails/integration_test/USAGE +1 -1
  145. data/lib/{generators → rails/generators}/rails/integration_test/integration_test_generator.rb +0 -0
  146. data/lib/{generators → rails/generators}/rails/mailer/USAGE +1 -1
  147. data/lib/{generators → rails/generators}/rails/mailer/mailer_generator.rb +0 -0
  148. data/lib/{generators → rails/generators}/rails/mailer/templates/mailer.rb +0 -0
  149. data/lib/{generators → rails/generators}/rails/metal/USAGE +1 -1
  150. data/lib/{generators → rails/generators}/rails/metal/metal_generator.rb +0 -0
  151. data/lib/{generators → rails/generators}/rails/metal/templates/metal.rb +0 -0
  152. data/lib/{generators → rails/generators}/rails/migration/USAGE +2 -2
  153. data/lib/{generators → rails/generators}/rails/migration/migration_generator.rb +0 -0
  154. data/lib/{generators → rails/generators}/rails/model/USAGE +2 -2
  155. data/lib/{generators → rails/generators}/rails/model/model_generator.rb +0 -0
  156. data/lib/{generators → rails/generators}/rails/observer/USAGE +1 -1
  157. data/lib/{generators → rails/generators}/rails/observer/observer_generator.rb +0 -0
  158. data/lib/{generators → rails/generators}/rails/performance_test/USAGE +1 -1
  159. data/lib/{generators → rails/generators}/rails/performance_test/performance_test_generator.rb +0 -0
  160. data/lib/{generators → rails/generators}/rails/plugin/USAGE +1 -1
  161. data/lib/{generators → rails/generators}/rails/plugin/plugin_generator.rb +1 -1
  162. data/lib/{generators → rails/generators}/rails/plugin/templates/MIT-LICENSE.tt +0 -0
  163. data/lib/{generators → rails/generators}/rails/plugin/templates/README.tt +0 -0
  164. data/lib/rails/generators/rails/plugin/templates/Rakefile.tt +23 -0
  165. data/lib/{generators → rails/generators}/rails/plugin/templates/init.rb +0 -0
  166. data/lib/{generators → rails/generators}/rails/plugin/templates/install.rb +0 -0
  167. data/lib/{generators → rails/generators}/rails/plugin/templates/lib/%file_name%.rb.tt +0 -0
  168. data/lib/{generators → rails/generators}/rails/plugin/templates/lib/tasks/%file_name%_tasks.rake.tt +0 -0
  169. data/lib/{generators → rails/generators}/rails/plugin/templates/uninstall.rb +0 -0
  170. data/lib/{generators → rails/generators}/rails/resource/USAGE +3 -3
  171. data/lib/{generators → rails/generators}/rails/resource/resource_generator.rb +3 -1
  172. data/lib/{generators → rails/generators}/rails/scaffold/USAGE +4 -4
  173. data/lib/{generators → rails/generators}/rails/scaffold/scaffold_generator.rb +1 -1
  174. data/lib/{generators → rails/generators}/rails/scaffold_controller/USAGE +1 -1
  175. data/lib/{generators → rails/generators}/rails/scaffold_controller/scaffold_controller_generator.rb +0 -0
  176. data/lib/{generators → rails/generators}/rails/scaffold_controller/templates/controller.rb +2 -2
  177. data/lib/{generators → rails/generators}/rails/session_migration/USAGE +1 -1
  178. data/lib/{generators → rails/generators}/rails/session_migration/session_migration_generator.rb +0 -0
  179. data/lib/{generators → rails/generators}/rails/stylesheets/USAGE +1 -1
  180. data/lib/{generators → rails/generators}/rails/stylesheets/stylesheets_generator.rb +0 -0
  181. data/lib/{generators → rails/generators}/rails/stylesheets/templates/scaffold.css +4 -0
  182. data/lib/{generators → rails/generators}/test_unit.rb +0 -0
  183. data/lib/{generators → rails/generators}/test_unit/controller/controller_generator.rb +2 -1
  184. data/lib/rails/generators/test_unit/controller/templates/functional_test.rb +18 -0
  185. data/lib/{generators → rails/generators}/test_unit/helper/helper_generator.rb +1 -1
  186. data/lib/{generators → rails/generators}/test_unit/helper/templates/helper_test.rb +0 -0
  187. data/lib/{generators → rails/generators}/test_unit/integration/integration_generator.rb +1 -1
  188. data/lib/{generators → rails/generators}/test_unit/integration/templates/integration_test.rb +0 -0
  189. data/lib/{generators → rails/generators}/test_unit/mailer/mailer_generator.rb +1 -8
  190. data/lib/rails/generators/test_unit/mailer/templates/functional_test.rb +20 -0
  191. data/lib/{generators → rails/generators}/test_unit/model/model_generator.rb +1 -1
  192. data/lib/{generators → rails/generators}/test_unit/model/templates/fixtures.yml +0 -0
  193. data/lib/{generators → rails/generators}/test_unit/model/templates/unit_test.rb +0 -0
  194. data/lib/{generators → rails/generators}/test_unit/observer/observer_generator.rb +1 -1
  195. data/lib/{generators → rails/generators}/test_unit/observer/templates/unit_test.rb +0 -0
  196. data/lib/{generators → rails/generators}/test_unit/performance/performance_generator.rb +1 -1
  197. data/lib/{generators → rails/generators}/test_unit/performance/templates/performance_test.rb +0 -0
  198. data/lib/{generators → rails/generators}/test_unit/plugin/plugin_generator.rb +1 -1
  199. data/lib/{generators → rails/generators}/test_unit/plugin/templates/%file_name%_test.rb.tt +0 -0
  200. data/lib/{generators → rails/generators}/test_unit/plugin/templates/test_helper.rb +0 -0
  201. data/lib/{generators → rails/generators}/test_unit/scaffold/scaffold_generator.rb +1 -1
  202. data/lib/{generators → rails/generators}/test_unit/scaffold/templates/functional_test.rb +9 -5
  203. data/{builtin/rails_info → lib}/rails/info.rb +0 -0
  204. data/{builtin/rails_info → lib}/rails/info_controller.rb +0 -0
  205. data/{builtin/routes.rb → lib/rails/info_routes.rb} +2 -2
  206. data/lib/rails/{subscriber.rb → log_subscriber.rb} +27 -27
  207. data/lib/rails/{subscriber → log_subscriber}/test_helper.rb +15 -16
  208. data/lib/rails/plugin.rb +31 -8
  209. data/lib/rails/rack/debugger.rb +3 -1
  210. data/lib/rails/rack/logger.rb +4 -4
  211. data/lib/rails/railtie.rb +179 -16
  212. data/lib/rails/railtie/configuration.rb +56 -1
  213. data/lib/rails/tasks/documentation.rake +38 -20
  214. data/lib/rails/tasks/framework.rake +16 -9
  215. data/lib/rails/tasks/misc.rake +3 -5
  216. data/lib/rails/tasks/routes.rake +2 -2
  217. data/lib/rails/test_help.rb +21 -1
  218. data/lib/rails/test_unit/railtie.rb +1 -3
  219. data/lib/rails/version.rb +3 -2
  220. metadata +199 -171
  221. data/builtin/rails_info/rails/info_helper.rb +0 -2
  222. data/lib/generators/erb.rb +0 -8
  223. data/lib/generators/erb/mailer/mailer_generator.rb +0 -20
  224. data/lib/generators/rails/app/templates/Gemfile +0 -34
  225. data/lib/generators/rails/app/templates/config/boot.rb +0 -17
  226. data/lib/generators/rails/app/templates/config/initializers/session_store.rb.tt +0 -15
  227. data/lib/generators/rails/model_subclass/model_subclass_generator.rb +0 -12
  228. data/lib/generators/rails/plugin/templates/Rakefile.tt +0 -10
  229. data/lib/generators/test_unit/controller/templates/functional_test.rb +0 -8
  230. data/lib/generators/test_unit/mailer/templates/fixture +0 -3
  231. data/lib/generators/test_unit/mailer/templates/functional_test.rb +0 -22
  232. data/lib/rails/railties_path.rb +0 -1
@@ -0,0 +1,20 @@
1
+ require 'test_helper'
2
+
3
+ class <%= class_name %>Test < ActionMailer::TestCase
4
+ <% for action in actions -%>
5
+ test "<%= action %>" do
6
+ mail = <%= class_name %>.<%= action %>
7
+ assert_equal <%= action.to_s.humanize.inspect %>, mail.subject
8
+ assert_equal ["to@example.org"], mail.to
9
+ assert_equal ["from@example.com"], mail.from
10
+ assert_match "Hi", mail.body.encoded
11
+ end
12
+
13
+ <% end -%>
14
+ <% if actions.blank? -%>
15
+ # replace this with your real tests
16
+ test "the truth" do
17
+ assert true
18
+ end
19
+ <% end -%>
20
+ end
@@ -1,4 +1,4 @@
1
- require 'generators/test_unit'
1
+ require 'rails/generators/test_unit'
2
2
 
3
3
  module TestUnit
4
4
  module Generators
@@ -1,4 +1,4 @@
1
- require 'generators/test_unit'
1
+ require 'rails/generators/test_unit'
2
2
 
3
3
  module TestUnit
4
4
  module Generators
@@ -1,4 +1,4 @@
1
- require 'generators/test_unit'
1
+ require 'rails/generators/test_unit'
2
2
 
3
3
  module TestUnit
4
4
  module Generators
@@ -1,4 +1,4 @@
1
- require 'generators/test_unit'
1
+ require 'rails/generators/test_unit'
2
2
 
3
3
  module TestUnit
4
4
  module Generators
@@ -1,4 +1,4 @@
1
- require 'generators/test_unit'
1
+ require 'rails/generators/test_unit'
2
2
  require 'rails/generators/resource_helpers'
3
3
 
4
4
  module TestUnit
@@ -1,6 +1,10 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class <%= controller_class_name %>ControllerTest < ActionController::TestCase
4
+ setup do
5
+ @<%= file_name %> = <%= table_name %>(:one)
6
+ end
7
+
4
8
  <% unless options[:singleton] -%>
5
9
  test "should get index" do
6
10
  get :index
@@ -16,30 +20,30 @@ class <%= controller_class_name %>ControllerTest < ActionController::TestCase
16
20
 
17
21
  test "should create <%= file_name %>" do
18
22
  assert_difference('<%= class_name %>.count') do
19
- post :create, :<%= file_name %> => <%= table_name %>(:one).attributes
23
+ post :create, :<%= file_name %> => @<%= file_name %>.attributes
20
24
  end
21
25
 
22
26
  assert_redirected_to <%= file_name %>_path(assigns(:<%= file_name %>))
23
27
  end
24
28
 
25
29
  test "should show <%= file_name %>" do
26
- get :show, :id => <%= table_name %>(:one).to_param
30
+ get :show, :id => @<%= file_name %>.to_param
27
31
  assert_response :success
28
32
  end
29
33
 
30
34
  test "should get edit" do
31
- get :edit, :id => <%= table_name %>(:one).to_param
35
+ get :edit, :id => @<%= file_name %>.to_param
32
36
  assert_response :success
33
37
  end
34
38
 
35
39
  test "should update <%= file_name %>" do
36
- put :update, :id => <%= table_name %>(:one).to_param, :<%= file_name %> => <%= table_name %>(:one).attributes
40
+ put :update, :id => @<%= file_name %>.to_param, :<%= file_name %> => @<%= file_name %>.attributes
37
41
  assert_redirected_to <%= file_name %>_path(assigns(:<%= file_name %>))
38
42
  end
39
43
 
40
44
  test "should destroy <%= file_name %>" do
41
45
  assert_difference('<%= class_name %>.count', -1) do
42
- delete :destroy, :id => <%= table_name %>(:one).to_param
46
+ delete :destroy, :id => @<%= file_name %>.to_param
43
47
  end
44
48
 
45
49
  assert_redirected_to <%= table_name %>_path
@@ -1,3 +1,3 @@
1
- ActionController::Routing::Routes.draw do |map|
1
+ Rails.application.routes.draw do |map|
2
2
  match '/rails/info/properties' => "rails/info#properties"
3
- end
3
+ end
@@ -2,15 +2,15 @@ require 'active_support/core_ext/class/inheritable_attributes'
2
2
  require 'active_support/notifications'
3
3
 
4
4
  module Rails
5
- # Rails::Subscriber is an object set to consume ActiveSupport::Notifications
6
- # on initialization with solely purpose of logging. The subscriber dispatches
5
+ # Rails::LogSubscriber is an object set to consume ActiveSupport::Notifications
6
+ # on initialization with solely purpose of logging. The log subscriber dispatches
7
7
  # notifications to a regirested object based on its given namespace.
8
8
  #
9
- # An example would be ActiveRecord subscriber responsible for logging queries:
9
+ # An example would be ActiveRecord log subscriber responsible for logging queries:
10
10
  #
11
11
  # module ActiveRecord
12
12
  # class Railtie
13
- # class Subscriber < Rails::Subscriber
13
+ # class LogSubscriber < Rails::LogSubscriber
14
14
  # def sql(event)
15
15
  # "#{event.payload[:name]} (#{event.duration}) #{event.payload[:sql]}"
16
16
  # end
@@ -20,19 +20,19 @@ module Rails
20
20
  #
21
21
  # It's finally registed as:
22
22
  #
23
- # Rails::Subscriber.add :active_record, ActiveRecord::Railtie::Subscriber.new
23
+ # Rails::LogSubscriber.add :active_record, ActiveRecord::Railtie::LogSubscriber.new
24
24
  #
25
- # So whenever a "active_record.sql" notification arrive to Rails::Subscriber,
25
+ # So whenever a "active_record.sql" notification arrive to Rails::LogSubscriber,
26
26
  # it will properly dispatch the event (ActiveSupport::Notifications::Event) to
27
27
  # the sql method.
28
28
  #
29
- # This is useful because it avoids spanning several subscribers just for logging
29
+ # This is useful because it avoids spanning several log subscribers just for logging
30
30
  # purposes(which slows down the main thread). Besides of providing a centralized
31
31
  # facility on top of Rails.logger.
32
- #
33
- # Subscriber also has some helpers to deal with logging and automatically flushes
32
+ #
33
+ # Log subscriber also has some helpers to deal with logging and automatically flushes
34
34
  # all logs when the request finishes (via action_dispatch.callback notification).
35
- class Subscriber
35
+ class LogSubscriber
36
36
  mattr_accessor :colorize_logging
37
37
  self.colorize_logging = true
38
38
 
@@ -50,30 +50,29 @@ module Rails
50
50
  CYAN = "\e[36m"
51
51
  WHITE = "\e[37m"
52
52
 
53
- def self.add(namespace, subscriber)
54
- subscribers[namespace.to_sym] = subscriber
55
- end
56
-
57
- def self.subscribers
58
- @subscribers ||= {}
59
- end
53
+ def self.add(namespace, log_subscriber, notifier = ActiveSupport::Notifications)
54
+ log_subscribers << log_subscriber
60
55
 
61
- def self.dispatch(args)
62
- namespace, name = args[0].split(".")
63
- subscriber = subscribers[namespace.to_sym]
56
+ log_subscriber.public_methods(false).each do |event|
57
+ notifier.subscribe("#{namespace}.#{event}") do |*args|
58
+ next if log_subscriber.logger.nil?
64
59
 
65
- if subscriber.respond_to?(name) && subscriber.logger
66
- begin
67
- subscriber.send(name, ActiveSupport::Notifications::Event.new(*args))
68
- rescue Exception => e
69
- Rails.logger.error "Could not log #{args[0].inspect} event. #{e.class}: #{e.message}"
60
+ begin
61
+ log_subscriber.send(event, ActiveSupport::Notifications::Event.new(*args))
62
+ rescue Exception => e
63
+ Rails.logger.error "Could not log #{args[0].inspect} event. #{e.class}: #{e.message}"
64
+ end
70
65
  end
71
66
  end
72
67
  end
73
68
 
74
- # Flush all subscribers' logger.
69
+ def self.log_subscribers
70
+ @log_subscribers ||= []
71
+ end
72
+
73
+ # Flush all log_subscribers' logger.
75
74
  def self.flush_all!
76
- loggers = subscribers.values.map(&:logger)
75
+ loggers = log_subscribers.map(&:logger)
77
76
  loggers.uniq!
78
77
  loggers.each { |l| l.flush if l.respond_to?(:flush) }
79
78
  end
@@ -88,6 +87,7 @@ module Rails
88
87
  %w(info debug warn error fatal unknown).each do |level|
89
88
  class_eval <<-METHOD, __FILE__, __LINE__ + 1
90
89
  def #{level}(*args, &block)
90
+ return unless logger
91
91
  logger.#{level}(*args, &block)
92
92
  end
93
93
  METHOD
@@ -1,13 +1,13 @@
1
- require 'rails/subscriber'
1
+ require 'rails/log_subscriber'
2
2
 
3
3
  module Rails
4
- class Subscriber
5
- # Provides some helpers to deal with testing subscribers by setting up
4
+ class LogSubscriber
5
+ # Provides some helpers to deal with testing log subscribers by setting up
6
6
  # notifications. Take for instance ActiveRecord subscriber tests:
7
7
  #
8
- # class SyncSubscriberTest < ActiveSupport::TestCase
9
- # include Rails::Subscriber::TestHelper
10
- # Rails::Subscriber.add(:active_record, ActiveRecord::Railties::Subscriber.new)
8
+ # class SyncLogSubscriberTest < ActiveSupport::TestCase
9
+ # include Rails::LogSubscriber::TestHelper
10
+ # Rails::LogSubscriber.add(:active_record, ActiveRecord::Railties::LogSubscriber.new)
11
11
  #
12
12
  # def test_basic_query_logging
13
13
  # Developer.all
@@ -17,18 +17,18 @@ module Rails
17
17
  # assert_match /SELECT \* FROM "developers"/, @logger.logged(:debug).last
18
18
  # end
19
19
  #
20
- # class SyncSubscriberTest < ActiveSupport::TestCase
21
- # include Rails::Subscriber::SyncTestHelper
22
- # include SubscriberTest
20
+ # class SyncLogSubscriberTest < ActiveSupport::TestCase
21
+ # include Rails::LogSubscriber::SyncTestHelper
22
+ # include LogSubscriberTest
23
23
  # end
24
24
  #
25
- # class AsyncSubscriberTest < ActiveSupport::TestCase
26
- # include Rails::Subscriber::AsyncTestHelper
27
- # include SubscriberTest
25
+ # class AsyncLogSubscriberTest < ActiveSupport::TestCase
26
+ # include Rails::LogSubscriber::AsyncTestHelper
27
+ # include LogSubscriberTest
28
28
  # end
29
29
  # end
30
30
  #
31
- # All you need to do is to ensure that your subscriber is added to Rails::Subscriber,
31
+ # All you need to do is to ensure that your log subscriber is added to Rails::Subscriber,
32
32
  # as in the second line of the code above. The test helpers is reponsible for setting
33
33
  # up the queue, subscriptions and turning colors in logs off.
34
34
  #
@@ -42,8 +42,7 @@ module Rails
42
42
  @logger = MockLogger.new
43
43
  @notifier = ActiveSupport::Notifications::Notifier.new(queue)
44
44
 
45
- Rails::Subscriber.colorize_logging = false
46
- @notifier.subscribe { |*args| Rails::Subscriber.dispatch(args) }
45
+ Rails::LogSubscriber.colorize_logging = false
47
46
 
48
47
  set_logger(@logger)
49
48
  ActiveSupport::Notifications.notifier = @notifier
@@ -80,7 +79,7 @@ module Rails
80
79
  @notifier.wait
81
80
  end
82
81
 
83
- # Overwrite if you use another logger in your subscriber:
82
+ # Overwrite if you use another logger in your log subscriber:
84
83
  #
85
84
  # def logger
86
85
  # ActiveRecord::Base.logger = @logger
@@ -1,6 +1,22 @@
1
1
  require 'rails/engine'
2
+ require 'active_support/core_ext/array/conversions'
2
3
 
3
4
  module Rails
5
+ # Rails::Plugin is nothing more than a Rails::Engine, but since it's loaded too late
6
+ # in the boot process, it does not have the same configuration powers as a bare
7
+ # Rails::Engine.
8
+ #
9
+ # Opposite to Rails::Railtie and Rails::Engine, you are not supposed to inherit from
10
+ # Rails::Plugin. Rails::Plugin is automatically configured to be an engine by simply
11
+ # placing inside vendor/plugins. Since this is done automatically, you actually cannot
12
+ # declare a Rails::Engine inside your Plugin, otherwise it would cause the same files
13
+ # to be loaded twice. This means that if you want to ship an Engine as gem it cannot
14
+ # be used as plugin and vice-versa.
15
+ #
16
+ # Besides this conceptual difference, the only difference between Rails::Engine and
17
+ # Rails::Plugin is that plugins automatically load the file "init.rb" at the plugin
18
+ # root during the boot process.
19
+ #
4
20
  class Plugin < Engine
5
21
  def self.inherited(base)
6
22
  raise "You cannot inherit from Rails::Plugin"
@@ -25,12 +41,14 @@ module Rails
25
41
 
26
42
  def load_tasks
27
43
  super
28
- extra_tasks = Dir["#{root}/{tasks,rails/tasks}/**/*.rake"]
44
+ load_deprecated_tasks
45
+ end
29
46
 
30
- unless extra_tasks.empty?
31
- ActiveSupport::Deprecation.warn "Having rake tasks in PLUGIN_PATH/tasks or " <<
32
- "PLUGIN_PATH/rails/tasks is deprecated. Use to PLUGIN_PATH/lib/tasks instead"
33
- extra_tasks.sort.each { |ext| load(ext) }
47
+ def load_deprecated_tasks
48
+ tasks = Dir["#{root}/{tasks,rails/tasks}/**/*.rake"].sort
49
+ if tasks.any?
50
+ ActiveSupport::Deprecation.warn "Rake tasks in #{tasks.to_sentence} are deprecated. Use lib/tasks instead"
51
+ tasks.each { |ext| load(ext) }
34
52
  end
35
53
  end
36
54
 
@@ -44,9 +62,14 @@ module Rails
44
62
  end
45
63
 
46
64
  initializer :load_init_rb, :before => :load_application_initializers do |app|
47
- file = Dir["#{root}/{rails/init,init}.rb"].first
48
- config = app.config
49
- eval(File.read(file), binding, file) if file && File.file?(file)
65
+ files = %w(rails/init.rb init.rb).map { |path| File.expand_path path, root }
66
+ if initrb = files.find { |path| File.file? path }
67
+ if initrb == files.first
68
+ ActiveSupport::Deprecation.warn "Use toplevel init.rb; rails/init.rb is deprecated: #{initrb}"
69
+ end
70
+ config = app.config
71
+ eval(File.read(initrb), binding, initrb)
72
+ end
50
73
  end
51
74
 
52
75
  initializer :sanity_check_railties_collision do
@@ -1,10 +1,12 @@
1
+ require 'active_support/core_ext/kernel/requires'
2
+
1
3
  module Rails
2
4
  module Rack
3
5
  class Debugger
4
6
  def initialize(app)
5
7
  @app = app
6
8
 
7
- ARGV.clear # clear ARGV so that script/server options aren't passed to IRB
9
+ ARGV.clear # clear ARGV so that rails server options aren't passed to IRB
8
10
 
9
11
  require_library_or_gem 'ruby-debug'
10
12
  ::Debugger.start
@@ -1,9 +1,9 @@
1
- require 'rails/subscriber'
1
+ require 'rails/log_subscriber'
2
2
 
3
3
  module Rails
4
4
  module Rack
5
5
  # Log the request started and flush all loggers after it.
6
- class Logger < Rails::Subscriber
6
+ class Logger < Rails::LogSubscriber
7
7
  def initialize(app)
8
8
  @app = app
9
9
  end
@@ -19,14 +19,14 @@ module Rails
19
19
 
20
20
  def before_dispatch(env)
21
21
  request = ActionDispatch::Request.new(env)
22
- path = request.request_uri.inspect rescue "unknown"
22
+ path = request.fullpath.inspect rescue "unknown"
23
23
 
24
24
  info "\n\nStarted #{request.method.to_s.upcase} #{path} " <<
25
25
  "for #{request.remote_ip} at #{Time.now.to_s(:db)}"
26
26
  end
27
27
 
28
28
  def after_dispatch(env)
29
- Rails::Subscriber.flush_all!
29
+ Rails::LogSubscriber.flush_all!
30
30
  end
31
31
 
32
32
  end
@@ -1,14 +1,185 @@
1
1
  require 'rails/initializable'
2
2
  require 'rails/configuration'
3
+ require 'active_support/inflector'
3
4
 
4
5
  module Rails
6
+ # Railtie is the core of the Rails Framework and provides several hooks to extend
7
+ # Rails and/or modify the initialization process.
8
+ #
9
+ # Every major component of Rails (Action Mailer, Action Controller,
10
+ # Action View, Active Record and Active Resource) are all Railties, so each of
11
+ # them is responsible to set their own initialization. This makes, for example,
12
+ # Rails absent of any ActiveRecord hook, allowing any other ORM framework to hook in.
13
+ #
14
+ # Developing a Rails extension does _not_ require any implementation of
15
+ # Railtie, but if you need to interact with the Rails framework during
16
+ # or after boot, then Railtie is what you need to do that interaction.
17
+ #
18
+ # For example, the following would need you to implement Railtie in your
19
+ # plugin:
20
+ #
21
+ # * creating initializers
22
+ # * configuring a Rails framework or the Application, like setting a generator
23
+ # * adding Rails config.* keys to the environment
24
+ # * setting up a subscriber to the Rails +ActiveSupport::Notifications+
25
+ # * adding rake tasks into rails
26
+ #
27
+ # == Creating your Railtie
28
+ #
29
+ # Implementing Railtie in your Rails extension is done by creating a class
30
+ # Railtie that has your extension name and making sure that this gets loaded
31
+ # during boot time of the Rails stack.
32
+ #
33
+ # You can do this however you wish, but here is an example if you want to provide
34
+ # it for a gem that can be used with or without Rails:
35
+ #
36
+ # * Create a file (say, lib/my_gem/railtie.rb) which contains class Railtie inheriting from
37
+ # Rails::Railtie and is namespaced to your gem:
38
+ #
39
+ # # lib/my_gem/railtie.rb
40
+ # module MyGem
41
+ # class Railtie < Rails::Railtie
42
+ # railtie_name :mygem
43
+ # end
44
+ # end
45
+ #
46
+ # * Require your own gem as well as rails in this file:
47
+ #
48
+ # # lib/my_gem/railtie.rb
49
+ # require 'my_gem'
50
+ # require 'rails'
51
+ #
52
+ # module MyGem
53
+ # class Railtie < Rails::Railtie
54
+ # railtie_name :mygem
55
+ # end
56
+ # end
57
+ #
58
+ # * Make sure your Gem loads the railtie.rb file if Rails is loaded first, an easy
59
+ # way to check is by checking for the Rails constant which will exist if Rails
60
+ # has started:
61
+ #
62
+ # # lib/my_gem.rb
63
+ # module MyGem
64
+ # require 'lib/my_gem/railtie' if defined?(Rails)
65
+ # end
66
+ #
67
+ # * Or instead of doing the require automatically, you can ask your users to require
68
+ # it for you in their Gemfile:
69
+ #
70
+ # # #{USER_RAILS_ROOT}/Gemfile
71
+ # gem "my_gem", :require_as => ["my_gem", "my_gem/railtie"]
72
+ #
73
+ # == Initializers
74
+ #
75
+ # To add an initialization step from your Railtie to Rails boot process, you just need
76
+ # to create an initializer block:
77
+ #
78
+ # class MyRailtie < Rails::Railtie
79
+ # initializer "my_railtie.configure_rails_initialization" do
80
+ # # some initialization behavior
81
+ # end
82
+ # end
83
+ #
84
+ # If specified, the block can also receive the application object, in case you
85
+ # need to access some application specific configuration:
86
+ #
87
+ # class MyRailtie < Rails::Railtie
88
+ # initializer "my_railtie.configure_rails_initialization" do |app|
89
+ # if app.config.cache_classes
90
+ # # some initialization behavior
91
+ # end
92
+ # end
93
+ # end
94
+ #
95
+ # Finally, you can also pass :before and :after as option to initializer, in case
96
+ # you want to couple it with a specific step in the initialization process.
97
+ #
98
+ # == Configuration
99
+ #
100
+ # Inside the Railtie class, you can access a config object which contains configuration
101
+ # shared by all railties and the application:
102
+ #
103
+ # class MyRailtie < Rails::Railtie
104
+ # # Customize the ORM
105
+ # config.generators.orm :my_railtie_orm
106
+ #
107
+ # # Add a middleware
108
+ # config.middlewares.use MyRailtie::Middleware
109
+ #
110
+ # # Add a to_prepare block which is executed once in production
111
+ # # and before which request in development
112
+ # config.to_prepare do
113
+ # MyRailtie.setup!
114
+ # end
115
+ # end
116
+ #
117
+ # == Loading rake tasks and generators
118
+ #
119
+ # If your railtie has rake tasks, you can tell Rails to load them through the method
120
+ # rake tasks:
121
+ #
122
+ # class MyRailtie < Railtie
123
+ # rake_tasks do
124
+ # load "path/to/my_railtie.tasks"
125
+ # end
126
+ # end
127
+ #
128
+ # By default, Rails load generators from your load path. However, if you want to place
129
+ # your generators at a different location, you can specify in your Railtie a block which
130
+ # will load them during normal generators lookup:
131
+ #
132
+ # class MyRailtie < Railtie
133
+ # generators do
134
+ # require "path/to/my_railtie_generator"
135
+ # end
136
+ # end
137
+ #
138
+ # == Adding your subscriber
139
+ #
140
+ # Since version 3.0, Rails ships with a notification system which is used for several
141
+ # purposes, including logging. If you are sending notifications in your Railtie, you may
142
+ # want to add a subscriber to consume such notifications for logging purposes.
143
+ #
144
+ # The subscriber is added under the railtie_name namespace and only consumes notifications
145
+ # under the given namespace. For example, let's suppose your railtie is publishing the
146
+ # following "something_expensive" instrumentation:
147
+ #
148
+ # ActiveSupport::Notifications.instrument "my_railtie.something_expensive" do
149
+ # # something expensive
150
+ # end
151
+ #
152
+ # You can log this instrumentation with your own Rails::Subscriber:
153
+ #
154
+ # class MyRailtie::Subscriber < Rails::Subscriber
155
+ # def something_expensive(event)
156
+ # info("Something expensive took %.1fms" % event.duration)
157
+ # end
158
+ # end
159
+ #
160
+ # By registering it:
161
+ #
162
+ # class MyRailtie < Railtie
163
+ # subscriber MyRailtie::Subscriber.new
164
+ # end
165
+ #
166
+ # Take a look in Rails::Subscriber docs for more information.
167
+ #
168
+ # == Application, Plugin and Engine
169
+ #
170
+ # A Rails::Engine is nothing more than a Railtie with some initializers already set.
171
+ # And since Rails::Application and Rails::Plugin are engines, the same configuration
172
+ # described here can be used in all three.
173
+ #
174
+ # Be sure to look at the documentation of those specific classes for more information.
175
+ #
5
176
  class Railtie
6
177
  autoload :Configurable, "rails/railtie/configurable"
7
178
  autoload :Configuration, "rails/railtie/configuration"
8
179
 
9
180
  include Initializable
10
181
 
11
- ABSTRACT_RAILTIES = %w(Rails::Plugin Rails::Engine Rails::Application)
182
+ ABSTRACT_RAILTIES = %w(Rails::Railtie Rails::Plugin Rails::Engine Rails::Application)
12
183
 
13
184
  class << self
14
185
  def subclasses
@@ -16,24 +187,18 @@ module Rails
16
187
  end
17
188
 
18
189
  def inherited(base)
19
- unless abstract_railtie?(base)
190
+ unless base.abstract_railtie?
20
191
  base.send(:include, self::Configurable)
21
192
  subclasses << base
22
193
  end
23
194
  end
24
195
 
25
- def railtie_name(railtie_name = nil)
26
- @railtie_name ||= name.demodulize.underscore
27
- @railtie_name = railtie_name if railtie_name
28
- @railtie_name
196
+ def railtie_name(*)
197
+ ActiveSupport::Deprecation.warn "railtie_name is deprecated and has no effect", caller
29
198
  end
30
199
 
31
- def railtie_names
32
- subclasses.map { |p| p.railtie_name }
33
- end
34
-
35
- def subscriber(subscriber)
36
- Rails::Subscriber.add(railtie_name, subscriber)
200
+ def log_subscriber(name, log_subscriber)
201
+ Rails::LogSubscriber.add(name, log_subscriber)
37
202
  end
38
203
 
39
204
  def rake_tasks(&blk)
@@ -48,10 +213,8 @@ module Rails
48
213
  @generators
49
214
  end
50
215
 
51
- protected
52
-
53
- def abstract_railtie?(base)
54
- ABSTRACT_RAILTIES.include?(base.name)
216
+ def abstract_railtie?
217
+ ABSTRACT_RAILTIES.include?(name)
55
218
  end
56
219
  end
57
220