railties 3.0.0.beta → 3.0.0.beta2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +15 -1
- data/README +9 -9
- data/bin/rails +28 -9
- data/guides/images/challenge.png +0 -0
- data/guides/images/edge_badge.png +0 -0
- data/guides/images/posts_index.png +0 -0
- data/guides/images/rails_welcome.png +0 -0
- data/guides/rails_guides.rb +9 -22
- data/guides/rails_guides/generator.rb +79 -50
- data/guides/rails_guides/textile_extensions.rb +3 -3
- data/guides/source/2_2_release_notes.textile +1 -1
- data/guides/source/2_3_release_notes.textile +1 -1
- data/guides/source/3_0_release_notes.textile +46 -38
- data/guides/source/action_controller_overview.textile +2 -2
- data/guides/source/action_mailer_basics.textile +4 -4
- data/guides/source/action_view_overview.textile +2 -2
- data/guides/source/active_record_querying.textile +73 -95
- data/guides/source/active_support_core_extensions.textile +993 -85
- data/guides/source/activerecord_validations_callbacks.textile +3 -3
- data/guides/source/caching_with_rails.textile +1 -1
- data/guides/source/command_line.textile +90 -88
- data/guides/source/configuring.textile +10 -10
- data/guides/source/contribute.textile +2 -2
- data/guides/source/contributing_to_rails.textile +14 -7
- data/guides/source/credits.textile.erb +8 -0
- data/guides/source/debugging_rails_applications.textile +6 -6
- data/guides/source/form_helpers.textile +1 -1
- data/guides/source/generators.textile +14 -14
- data/guides/source/getting_started.textile +634 -500
- data/guides/source/index.textile.erb +16 -1
- data/guides/source/layout.html.erb +7 -1
- data/guides/source/layouts_and_rendering.textile +299 -71
- data/guides/source/migrations.textile +5 -5
- data/guides/source/performance_testing.textile +8 -8
- data/guides/source/plugins.textile +26 -24
- data/guides/source/rails_on_rack.textile +5 -5
- data/guides/source/routing.textile +119 -117
- data/guides/source/security.textile +1 -1
- data/guides/source/testing.textile +4 -4
- data/lib/rails.rb +4 -1
- data/lib/rails/application.rb +44 -7
- data/lib/rails/application/bootstrap.rb +2 -14
- data/lib/rails/application/configuration.rb +69 -5
- data/lib/rails/application/finisher.rb +2 -3
- data/lib/rails/application/metal_loader.rb +1 -1
- data/lib/rails/application/routes_reloader.rb +1 -1
- data/lib/rails/backtrace_cleaner.rb +0 -11
- data/lib/rails/commands.rb +7 -6
- data/lib/rails/commands/application.rb +1 -1
- data/lib/rails/commands/console.rb +1 -1
- data/lib/rails/commands/dbconsole.rb +12 -0
- data/lib/rails/commands/destroy.rb +2 -2
- data/lib/rails/commands/generate.rb +2 -2
- data/lib/rails/commands/performance/benchmarker.rb +2 -2
- data/lib/rails/commands/performance/profiler.rb +2 -2
- data/lib/rails/commands/plugin.rb +6 -6
- data/lib/rails/commands/runner.rb +2 -0
- data/lib/rails/commands/server.rb +23 -8
- data/lib/rails/configuration.rb +2 -84
- data/lib/rails/console/app.rb +4 -3
- data/lib/rails/console/helpers.rb +3 -1
- data/lib/rails/engine.rb +107 -12
- data/lib/rails/engine/configuration.rb +8 -2
- data/lib/rails/generators.rb +22 -7
- data/lib/rails/generators/actions.rb +16 -6
- data/lib/rails/generators/base.rb +15 -8
- data/lib/rails/generators/erb.rb +21 -0
- data/lib/{generators → rails/generators}/erb/controller/controller_generator.rb +4 -5
- data/lib/{generators → rails/generators}/erb/controller/templates/view.html.erb +0 -0
- data/lib/rails/generators/erb/mailer/mailer_generator.rb +13 -0
- data/lib/{generators → rails/generators}/erb/mailer/templates/view.text.erb +0 -0
- data/lib/{generators → rails/generators}/erb/scaffold/scaffold_generator.rb +14 -26
- data/lib/{generators → rails/generators}/erb/scaffold/templates/_form.html.erb +1 -1
- data/lib/{generators → rails/generators}/erb/scaffold/templates/edit.html.erb +0 -0
- data/lib/{generators → rails/generators}/erb/scaffold/templates/index.html.erb +1 -1
- data/lib/{generators → rails/generators}/erb/scaffold/templates/layout.html.erb +1 -0
- data/lib/{generators → rails/generators}/erb/scaffold/templates/new.html.erb +0 -0
- data/lib/{generators → rails/generators}/erb/scaffold/templates/show.html.erb +0 -0
- data/lib/rails/generators/named_base.rb +4 -0
- data/lib/{generators → rails/generators}/rails/app/USAGE +0 -0
- data/lib/{generators → rails/generators}/rails/app/app_generator.rb +21 -7
- data/lib/rails/generators/rails/app/templates/Gemfile +34 -0
- data/lib/{generators → rails/generators}/rails/app/templates/README +9 -8
- data/lib/{generators → rails/generators}/rails/app/templates/Rakefile +0 -0
- data/lib/{generators → rails/generators}/rails/app/templates/app/controllers/application_controller.rb +0 -0
- data/lib/{generators → rails/generators}/rails/app/templates/app/helpers/application_helper.rb +0 -0
- data/lib/{generators → rails/generators}/rails/app/templates/app/models/.empty_directory +0 -0
- data/lib/{generators → rails/generators}/rails/app/templates/app/views/layouts/.empty_directory +0 -0
- data/lib/{generators → rails/generators}/rails/app/templates/config.ru +0 -0
- data/lib/{generators → rails/generators}/rails/app/templates/config/application.rb +4 -3
- data/lib/rails/generators/rails/app/templates/config/boot.rb +14 -0
- data/lib/{generators → rails/generators}/rails/app/templates/config/databases/frontbase.yml +0 -0
- data/lib/{generators → rails/generators}/rails/app/templates/config/databases/ibm_db.yml +0 -0
- data/lib/{generators → rails/generators}/rails/app/templates/config/databases/mysql.yml +0 -0
- data/lib/{generators → rails/generators}/rails/app/templates/config/databases/oracle.yml +0 -0
- data/lib/{generators → rails/generators}/rails/app/templates/config/databases/postgresql.yml +0 -0
- data/lib/{generators → rails/generators}/rails/app/templates/config/databases/sqlite3.yml +0 -0
- data/lib/{generators → rails/generators}/rails/app/templates/config/environment.rb +0 -0
- data/lib/{generators → rails/generators}/rails/app/templates/config/environments/development.rb.tt +0 -0
- data/lib/{generators → rails/generators}/rails/app/templates/config/environments/production.rb.tt +9 -0
- data/lib/{generators → rails/generators}/rails/app/templates/config/environments/test.rb.tt +0 -0
- data/lib/{generators → rails/generators}/rails/app/templates/config/initializers/backtrace_silencers.rb +0 -0
- data/lib/{generators → rails/generators}/rails/app/templates/config/initializers/cookie_verification_secret.rb.tt +1 -1
- data/lib/{generators → rails/generators}/rails/app/templates/config/initializers/inflections.rb +0 -0
- data/lib/{generators → rails/generators}/rails/app/templates/config/initializers/mime_types.rb +0 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +10 -0
- data/lib/{generators → rails/generators}/rails/app/templates/config/locales/en.yml +0 -0
- data/lib/{generators → rails/generators}/rails/app/templates/config/routes.rb +0 -0
- data/lib/{generators → rails/generators}/rails/app/templates/db/seeds.rb +0 -0
- data/lib/{generators → rails/generators}/rails/app/templates/doc/README_FOR_APP +0 -0
- data/lib/{generators → rails/generators}/rails/app/templates/gitignore +0 -0
- data/lib/{generators → rails/generators}/rails/app/templates/public/404.html +0 -0
- data/lib/{generators → rails/generators}/rails/app/templates/public/422.html +0 -0
- data/lib/{generators → rails/generators}/rails/app/templates/public/500.html +0 -0
- data/lib/{generators → rails/generators}/rails/app/templates/public/favicon.ico +0 -0
- data/lib/{generators → rails/generators}/rails/app/templates/public/images/rails.png +0 -0
- data/lib/{generators → rails/generators}/rails/app/templates/public/index.html +17 -17
- data/lib/{generators → rails/generators}/rails/app/templates/public/javascripts/application.js +0 -0
- data/lib/{generators → rails/generators}/rails/app/templates/public/javascripts/controls.js +5 -3
- data/lib/{generators → rails/generators}/rails/app/templates/public/javascripts/dragdrop.js +7 -6
- data/lib/{generators → rails/generators}/rails/app/templates/public/javascripts/effects.js +8 -13
- data/lib/{generators → rails/generators}/rails/app/templates/public/javascripts/prototype.js +1573 -1019
- data/lib/{generators → rails/generators}/rails/app/templates/public/javascripts/rails.js +1 -2
- data/lib/{generators → rails/generators}/rails/app/templates/public/robots.txt +0 -0
- data/lib/{generators → rails/generators}/rails/app/templates/public/stylesheets/.empty_directory +0 -0
- data/lib/{generators → rails/generators}/rails/app/templates/script/rails +0 -1
- data/lib/{generators → rails/generators}/rails/app/templates/test/fixtures/.empty_directory +0 -0
- data/lib/{generators → rails/generators}/rails/app/templates/test/functional/.empty_directory +0 -0
- data/lib/{generators → rails/generators}/rails/app/templates/test/integration/.empty_directory +0 -0
- data/lib/{generators → rails/generators}/rails/app/templates/test/performance/browsing_test.rb +1 -1
- data/lib/{generators → rails/generators}/rails/app/templates/test/test_helper.rb +1 -1
- data/lib/{generators → rails/generators}/rails/app/templates/test/unit/.empty_directory +0 -0
- data/lib/{generators → rails/generators}/rails/controller/USAGE +1 -1
- data/lib/{generators → rails/generators}/rails/controller/controller_generator.rb +6 -0
- data/lib/{generators → rails/generators}/rails/controller/templates/controller.rb +0 -0
- data/lib/{generators → rails/generators}/rails/generator/USAGE +1 -1
- data/lib/{generators → rails/generators}/rails/generator/generator_generator.rb +0 -0
- data/lib/{generators → rails/generators}/rails/generator/templates/%file_name%_generator.rb.tt +0 -0
- data/lib/{generators → rails/generators}/rails/generator/templates/USAGE.tt +1 -1
- data/lib/{generators → rails/generators}/rails/generator/templates/templates/.empty_directory +0 -0
- data/lib/{generators → rails/generators}/rails/helper/USAGE +1 -1
- data/lib/{generators → rails/generators}/rails/helper/helper_generator.rb +0 -0
- data/lib/{generators → rails/generators}/rails/helper/templates/helper.rb +0 -0
- data/lib/{generators → rails/generators}/rails/integration_test/USAGE +1 -1
- data/lib/{generators → rails/generators}/rails/integration_test/integration_test_generator.rb +0 -0
- data/lib/{generators → rails/generators}/rails/mailer/USAGE +1 -1
- data/lib/{generators → rails/generators}/rails/mailer/mailer_generator.rb +0 -0
- data/lib/{generators → rails/generators}/rails/mailer/templates/mailer.rb +0 -0
- data/lib/{generators → rails/generators}/rails/metal/USAGE +1 -1
- data/lib/{generators → rails/generators}/rails/metal/metal_generator.rb +0 -0
- data/lib/{generators → rails/generators}/rails/metal/templates/metal.rb +0 -0
- data/lib/{generators → rails/generators}/rails/migration/USAGE +2 -2
- data/lib/{generators → rails/generators}/rails/migration/migration_generator.rb +0 -0
- data/lib/{generators → rails/generators}/rails/model/USAGE +2 -2
- data/lib/{generators → rails/generators}/rails/model/model_generator.rb +0 -0
- data/lib/{generators → rails/generators}/rails/observer/USAGE +1 -1
- data/lib/{generators → rails/generators}/rails/observer/observer_generator.rb +0 -0
- data/lib/{generators → rails/generators}/rails/performance_test/USAGE +1 -1
- data/lib/{generators → rails/generators}/rails/performance_test/performance_test_generator.rb +0 -0
- data/lib/{generators → rails/generators}/rails/plugin/USAGE +1 -1
- data/lib/{generators → rails/generators}/rails/plugin/plugin_generator.rb +1 -1
- data/lib/{generators → rails/generators}/rails/plugin/templates/MIT-LICENSE.tt +0 -0
- data/lib/{generators → rails/generators}/rails/plugin/templates/README.tt +0 -0
- data/lib/rails/generators/rails/plugin/templates/Rakefile.tt +23 -0
- data/lib/{generators → rails/generators}/rails/plugin/templates/init.rb +0 -0
- data/lib/{generators → rails/generators}/rails/plugin/templates/install.rb +0 -0
- data/lib/{generators → rails/generators}/rails/plugin/templates/lib/%file_name%.rb.tt +0 -0
- data/lib/{generators → rails/generators}/rails/plugin/templates/lib/tasks/%file_name%_tasks.rake.tt +0 -0
- data/lib/{generators → rails/generators}/rails/plugin/templates/uninstall.rb +0 -0
- data/lib/{generators → rails/generators}/rails/resource/USAGE +3 -3
- data/lib/{generators → rails/generators}/rails/resource/resource_generator.rb +3 -1
- data/lib/{generators → rails/generators}/rails/scaffold/USAGE +4 -4
- data/lib/{generators → rails/generators}/rails/scaffold/scaffold_generator.rb +1 -1
- data/lib/{generators → rails/generators}/rails/scaffold_controller/USAGE +1 -1
- data/lib/{generators → rails/generators}/rails/scaffold_controller/scaffold_controller_generator.rb +0 -0
- data/lib/{generators → rails/generators}/rails/scaffold_controller/templates/controller.rb +2 -2
- data/lib/{generators → rails/generators}/rails/session_migration/USAGE +1 -1
- data/lib/{generators → rails/generators}/rails/session_migration/session_migration_generator.rb +0 -0
- data/lib/{generators → rails/generators}/rails/stylesheets/USAGE +1 -1
- data/lib/{generators → rails/generators}/rails/stylesheets/stylesheets_generator.rb +0 -0
- data/lib/{generators → rails/generators}/rails/stylesheets/templates/scaffold.css +4 -0
- data/lib/{generators → rails/generators}/test_unit.rb +0 -0
- data/lib/{generators → rails/generators}/test_unit/controller/controller_generator.rb +2 -1
- data/lib/rails/generators/test_unit/controller/templates/functional_test.rb +18 -0
- data/lib/{generators → rails/generators}/test_unit/helper/helper_generator.rb +1 -1
- data/lib/{generators → rails/generators}/test_unit/helper/templates/helper_test.rb +0 -0
- data/lib/{generators → rails/generators}/test_unit/integration/integration_generator.rb +1 -1
- data/lib/{generators → rails/generators}/test_unit/integration/templates/integration_test.rb +0 -0
- data/lib/{generators → rails/generators}/test_unit/mailer/mailer_generator.rb +1 -8
- data/lib/rails/generators/test_unit/mailer/templates/functional_test.rb +20 -0
- data/lib/{generators → rails/generators}/test_unit/model/model_generator.rb +1 -1
- data/lib/{generators → rails/generators}/test_unit/model/templates/fixtures.yml +0 -0
- data/lib/{generators → rails/generators}/test_unit/model/templates/unit_test.rb +0 -0
- data/lib/{generators → rails/generators}/test_unit/observer/observer_generator.rb +1 -1
- data/lib/{generators → rails/generators}/test_unit/observer/templates/unit_test.rb +0 -0
- data/lib/{generators → rails/generators}/test_unit/performance/performance_generator.rb +1 -1
- data/lib/{generators → rails/generators}/test_unit/performance/templates/performance_test.rb +0 -0
- data/lib/{generators → rails/generators}/test_unit/plugin/plugin_generator.rb +1 -1
- data/lib/{generators → rails/generators}/test_unit/plugin/templates/%file_name%_test.rb.tt +0 -0
- data/lib/{generators → rails/generators}/test_unit/plugin/templates/test_helper.rb +0 -0
- data/lib/{generators → rails/generators}/test_unit/scaffold/scaffold_generator.rb +1 -1
- data/lib/{generators → rails/generators}/test_unit/scaffold/templates/functional_test.rb +9 -5
- data/{builtin/rails_info → lib}/rails/info.rb +0 -0
- data/{builtin/rails_info → lib}/rails/info_controller.rb +0 -0
- data/{builtin/routes.rb → lib/rails/info_routes.rb} +2 -2
- data/lib/rails/{subscriber.rb → log_subscriber.rb} +27 -27
- data/lib/rails/{subscriber → log_subscriber}/test_helper.rb +15 -16
- data/lib/rails/plugin.rb +31 -8
- data/lib/rails/rack/debugger.rb +3 -1
- data/lib/rails/rack/logger.rb +4 -4
- data/lib/rails/railtie.rb +179 -16
- data/lib/rails/railtie/configuration.rb +56 -1
- data/lib/rails/tasks/documentation.rake +38 -20
- data/lib/rails/tasks/framework.rake +16 -9
- data/lib/rails/tasks/misc.rake +3 -5
- data/lib/rails/tasks/routes.rake +2 -2
- data/lib/rails/test_help.rb +21 -1
- data/lib/rails/test_unit/railtie.rb +1 -3
- data/lib/rails/version.rb +3 -2
- metadata +199 -171
- data/builtin/rails_info/rails/info_helper.rb +0 -2
- data/lib/generators/erb.rb +0 -8
- data/lib/generators/erb/mailer/mailer_generator.rb +0 -20
- data/lib/generators/rails/app/templates/Gemfile +0 -34
- data/lib/generators/rails/app/templates/config/boot.rb +0 -17
- data/lib/generators/rails/app/templates/config/initializers/session_store.rb.tt +0 -15
- data/lib/generators/rails/model_subclass/model_subclass_generator.rb +0 -12
- data/lib/generators/rails/plugin/templates/Rakefile.tt +0 -10
- data/lib/generators/test_unit/controller/templates/functional_test.rb +0 -8
- data/lib/generators/test_unit/mailer/templates/fixture +0 -3
- data/lib/generators/test_unit/mailer/templates/functional_test.rb +0 -22
- 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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
data/lib/{generators → rails/generators}/test_unit/performance/templates/performance_test.rb
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -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 %> =>
|
|
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 =>
|
|
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 =>
|
|
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 =>
|
|
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 =>
|
|
46
|
+
delete :destroy, :id => @<%= file_name %>.to_param
|
|
43
47
|
end
|
|
44
48
|
|
|
45
49
|
assert_redirected_to <%= table_name %>_path
|
|
File without changes
|
|
File without changes
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
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::
|
|
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
|
|
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::
|
|
23
|
+
# Rails::LogSubscriber.add :active_record, ActiveRecord::Railtie::LogSubscriber.new
|
|
24
24
|
#
|
|
25
|
-
# So whenever a "active_record.sql" notification arrive to Rails::
|
|
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
|
-
#
|
|
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
|
|
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,
|
|
54
|
-
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
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 =
|
|
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/
|
|
1
|
+
require 'rails/log_subscriber'
|
|
2
2
|
|
|
3
3
|
module Rails
|
|
4
|
-
class
|
|
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
|
|
9
|
-
# include Rails::
|
|
10
|
-
# Rails::
|
|
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
|
|
21
|
-
# include Rails::
|
|
22
|
-
# include
|
|
20
|
+
# class SyncLogSubscriberTest < ActiveSupport::TestCase
|
|
21
|
+
# include Rails::LogSubscriber::SyncTestHelper
|
|
22
|
+
# include LogSubscriberTest
|
|
23
23
|
# end
|
|
24
24
|
#
|
|
25
|
-
# class
|
|
26
|
-
# include Rails::
|
|
27
|
-
# include
|
|
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::
|
|
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
|
data/lib/rails/plugin.rb
CHANGED
|
@@ -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
|
-
|
|
44
|
+
load_deprecated_tasks
|
|
45
|
+
end
|
|
29
46
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
data/lib/rails/rack/debugger.rb
CHANGED
|
@@ -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
|
|
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
|
data/lib/rails/rack/logger.rb
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
require 'rails/
|
|
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::
|
|
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.
|
|
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::
|
|
29
|
+
Rails::LogSubscriber.flush_all!
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
end
|
data/lib/rails/railtie.rb
CHANGED
|
@@ -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?
|
|
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(
|
|
26
|
-
|
|
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
|
|
32
|
-
|
|
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
|
-
|
|
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
|
|