railties 3.1.12 → 3.2.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +2292 -41
- data/README.rdoc +14 -5
- data/bin/rails +7 -0
- data/guides/code/getting_started/Gemfile +27 -0
- data/guides/code/getting_started/README.rdoc +261 -0
- data/guides/code/getting_started/Rakefile +7 -0
- data/guides/code/getting_started/app/assets/images/rails.png +0 -0
- data/guides/code/getting_started/app/assets/javascripts/application.js +9 -0
- data/guides/code/getting_started/app/assets/javascripts/comments.js.coffee +3 -0
- data/guides/code/getting_started/app/assets/javascripts/home.js.coffee +3 -0
- data/guides/code/getting_started/app/assets/javascripts/posts.js.coffee +3 -0
- data/guides/code/getting_started/app/assets/stylesheets/application.css +7 -0
- data/guides/code/getting_started/app/assets/stylesheets/comments.css.scss +3 -0
- data/guides/code/getting_started/app/assets/stylesheets/home.css.scss +3 -0
- data/guides/code/getting_started/app/assets/stylesheets/posts.css.scss +3 -0
- data/guides/code/getting_started/app/assets/stylesheets/scaffolds.css.scss +56 -0
- data/guides/code/getting_started/app/controllers/application_controller.rb +3 -0
- data/guides/code/getting_started/app/controllers/comments_controller.rb +16 -0
- data/guides/code/getting_started/app/controllers/home_controller.rb +5 -0
- data/guides/code/getting_started/app/controllers/posts_controller.rb +84 -0
- data/guides/code/getting_started/app/helpers/application_helper.rb +2 -0
- data/guides/code/getting_started/app/helpers/comments_helper.rb +2 -0
- data/guides/code/getting_started/app/helpers/home_helper.rb +2 -0
- data/guides/code/getting_started/app/helpers/posts_helper.rb +5 -0
- data/guides/code/getting_started/app/models/comment.rb +3 -0
- data/guides/code/getting_started/app/models/post.rb +11 -0
- data/guides/code/getting_started/app/models/tag.rb +3 -0
- data/guides/code/getting_started/app/views/comments/_comment.html.erb +15 -0
- data/guides/code/getting_started/app/views/comments/_form.html.erb +13 -0
- data/guides/code/getting_started/app/views/home/index.html.erb +2 -0
- data/guides/code/getting_started/app/views/layouts/application.html.erb +14 -0
- data/guides/code/getting_started/app/views/posts/_form.html.erb +32 -0
- data/guides/code/getting_started/app/views/posts/edit.html.erb +6 -0
- data/guides/code/getting_started/app/views/posts/index.html.erb +27 -0
- data/guides/code/getting_started/app/views/posts/new.html.erb +5 -0
- data/guides/code/getting_started/app/views/posts/show.html.erb +31 -0
- data/guides/code/getting_started/app/views/tags/_form.html.erb +12 -0
- data/guides/code/getting_started/config.ru +4 -0
- data/guides/code/getting_started/config/application.rb +53 -0
- data/guides/code/getting_started/config/boot.rb +6 -0
- data/guides/code/getting_started/config/database.yml +25 -0
- data/guides/code/getting_started/config/environment.rb +5 -0
- data/guides/code/getting_started/config/environments/development.rb +37 -0
- data/guides/code/getting_started/config/environments/production.rb +67 -0
- data/guides/code/getting_started/config/environments/test.rb +37 -0
- data/guides/code/getting_started/config/initializers/backtrace_silencers.rb +7 -0
- data/guides/code/getting_started/config/initializers/inflections.rb +10 -0
- data/guides/code/getting_started/config/initializers/mime_types.rb +5 -0
- data/guides/code/getting_started/config/initializers/secret_token.rb +7 -0
- data/guides/code/getting_started/config/initializers/session_store.rb +8 -0
- data/guides/code/getting_started/config/initializers/wrap_parameters.rb +14 -0
- data/guides/code/getting_started/config/locales/en.yml +5 -0
- data/guides/code/getting_started/config/routes.rb +64 -0
- data/guides/code/getting_started/db/migrate/20110901012504_create_posts.rb +11 -0
- data/guides/code/getting_started/db/migrate/20110901012815_create_comments.rb +12 -0
- data/guides/code/getting_started/db/migrate/20110901013701_create_tags.rb +11 -0
- data/guides/code/getting_started/db/schema.rb +43 -0
- data/guides/code/getting_started/db/seeds.rb +7 -0
- data/guides/code/getting_started/doc/README_FOR_APP +2 -0
- data/guides/code/getting_started/public/404.html +26 -0
- data/guides/code/getting_started/public/422.html +26 -0
- data/guides/code/getting_started/public/500.html +26 -0
- data/guides/code/getting_started/public/favicon.ico +0 -0
- data/guides/code/getting_started/public/robots.txt +5 -0
- data/guides/code/getting_started/script/rails +6 -0
- data/guides/code/getting_started/test/fixtures/comments.yml +11 -0
- data/guides/code/getting_started/test/fixtures/posts.yml +11 -0
- data/guides/code/getting_started/test/fixtures/tags.yml +9 -0
- data/guides/code/getting_started/test/functional/comments_controller_test.rb +7 -0
- data/guides/code/getting_started/test/functional/home_controller_test.rb +9 -0
- data/guides/code/getting_started/test/functional/posts_controller_test.rb +49 -0
- data/guides/code/getting_started/test/performance/browsing_test.rb +12 -0
- data/guides/code/getting_started/test/test_helper.rb +13 -0
- data/guides/code/getting_started/test/unit/comment_test.rb +7 -0
- data/guides/code/getting_started/test/unit/helpers/comments_helper_test.rb +4 -0
- data/guides/code/getting_started/test/unit/helpers/home_helper_test.rb +4 -0
- data/guides/code/getting_started/test/unit/helpers/posts_helper_test.rb +4 -0
- data/guides/code/getting_started/test/unit/post_test.rb +7 -0
- data/guides/code/getting_started/test/unit/tag_test.rb +7 -0
- data/guides/rails_guides/generator.rb +2 -1
- data/guides/source/3_0_release_notes.textile +2 -2
- data/guides/source/3_1_release_notes.textile +3 -110
- data/guides/source/action_controller_overview.textile +11 -13
- data/guides/source/action_mailer_basics.textile +7 -18
- data/guides/source/action_view_overview.textile +78 -9
- data/guides/source/active_model_basics.textile +205 -0
- data/guides/source/active_record_basics.textile +31 -31
- data/guides/source/active_record_querying.textile +288 -67
- data/guides/source/active_record_validations_callbacks.textile +69 -75
- data/guides/source/active_resource_basics.textile +48 -2
- data/guides/source/active_support_core_extensions.textile +145 -24
- data/guides/source/ajax_on_rails.textile +65 -7
- data/guides/source/api_documentation_guidelines.textile +0 -6
- data/guides/source/asset_pipeline.textile +2 -2
- data/guides/source/association_basics.textile +25 -34
- data/guides/source/caching_with_rails.textile +12 -17
- data/guides/source/command_line.textile +29 -19
- data/guides/source/configuring.textile +40 -18
- data/guides/source/contributing_to_ruby_on_rails.textile +11 -18
- data/guides/source/debugging_rails_applications.textile +10 -21
- data/guides/source/engines.textile +618 -0
- data/guides/source/form_helpers.textile +1 -12
- data/guides/source/generators.textile +9 -11
- data/guides/source/getting_started.textile +152 -152
- data/guides/source/i18n.textile +4 -5
- data/guides/source/index.html.erb +0 -1
- data/guides/source/initialization.textile +26 -26
- data/guides/source/layouts_and_rendering.textile +97 -61
- data/guides/source/migrations.textile +380 -161
- data/guides/source/performance_testing.textile +4 -10
- data/guides/source/plugins.textile +11 -19
- data/guides/source/rails_application_templates.textile +12 -4
- data/guides/source/rails_on_rack.textile +25 -19
- data/guides/source/routing.textile +6 -13
- data/guides/source/ruby_on_rails_guides_guidelines.textile +0 -5
- data/guides/source/security.textile +11 -15
- data/guides/source/testing.textile +1 -9
- data/lib/rails/application.rb +107 -42
- data/lib/rails/application/bootstrap.rb +12 -11
- data/lib/rails/application/configuration.rb +27 -21
- data/lib/rails/application/finisher.rb +40 -17
- data/lib/rails/application/route_inspector.rb +75 -0
- data/lib/rails/application/routes_reloader.rb +15 -4
- data/lib/rails/code_statistics.rb +16 -5
- data/lib/rails/commands.rb +6 -5
- data/lib/rails/commands/application.rb +8 -1
- data/lib/rails/commands/console.rb +2 -0
- data/lib/rails/commands/dbconsole.rb +2 -2
- data/lib/rails/commands/destroy.rb +0 -2
- data/lib/rails/commands/generate.rb +3 -3
- data/lib/rails/commands/plugin.rb +161 -159
- data/lib/rails/commands/plugin_new.rb +3 -2
- data/lib/rails/commands/runner.rb +4 -0
- data/lib/rails/console/app.rb +26 -22
- data/lib/rails/console/helpers.rb +9 -5
- data/lib/rails/engine.rb +70 -34
- data/lib/rails/engine/commands.rb +39 -0
- data/lib/rails/engine/configuration.rb +1 -1
- data/lib/rails/generators.rb +3 -14
- data/lib/rails/generators/actions.rb +36 -9
- data/lib/rails/generators/app_base.rb +34 -38
- data/lib/rails/generators/base.rb +4 -4
- data/lib/rails/generators/generated_attribute.rb +1 -1
- data/lib/rails/generators/named_base.rb +1 -3
- data/lib/rails/generators/rails/app/USAGE +6 -0
- data/lib/rails/generators/rails/app/app_generator.rb +6 -2
- data/lib/rails/generators/rails/app/templates/Gemfile +4 -3
- data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +9 -3
- data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +11 -5
- data/lib/rails/generators/rails/app/templates/app/mailers/.empty_directory +0 -0
- data/lib/rails/generators/rails/app/templates/app/models/.empty_directory +0 -0
- data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/application.rb +11 -0
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml +1 -1
- data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml +1 -1
- data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +10 -1
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +10 -1
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +6 -6
- data/lib/rails/generators/rails/app/templates/config/initializers/inflections.rb +5 -0
- data/lib/rails/generators/rails/app/templates/config/routes.rb +1 -1
- data/lib/rails/generators/rails/app/templates/public/500.html +0 -1
- data/lib/rails/generators/rails/app/templates/public/index.html +1 -1
- data/lib/rails/generators/rails/app/templates/public/stylesheets/.empty_directory +0 -0
- data/lib/rails/generators/rails/app/templates/test/fixtures/.empty_directory +0 -0
- data/lib/rails/generators/rails/app/templates/test/functional/.empty_directory +0 -0
- data/lib/rails/generators/rails/app/templates/test/integration/.empty_directory +0 -0
- data/lib/rails/generators/rails/app/templates/test/unit/.empty_directory +0 -0
- data/lib/rails/generators/rails/controller/templates/controller.rb +1 -1
- data/lib/rails/generators/rails/generator/templates/templates/.empty_directory +0 -0
- data/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb +17 -5
- data/lib/rails/generators/rails/plugin_new/templates/Rakefile +1 -0
- data/lib/rails/generators/rails/plugin_new/templates/app/mailers/.empty_directory +0 -0
- data/lib/rails/generators/rails/plugin_new/templates/app/models/.empty_directory +0 -0
- data/lib/rails/generators/rails/plugin_new/templates/app/views/layouts/%name%/application.html.erb.tt +1 -1
- data/lib/rails/generators/rails/plugin_new/templates/gitignore +4 -3
- data/lib/rails/generators/rails/plugin_new/templates/lib/%name%/engine.rb +1 -1
- data/lib/rails/generators/rails/plugin_new/templates/rails/application.rb +1 -1
- data/lib/rails/generators/rails/plugin_new/templates/script/rails.tt +5 -3
- data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +2 -2
- data/lib/rails/generators/rails/task/USAGE +9 -0
- data/lib/rails/generators/rails/task/task_generator.rb +12 -0
- data/lib/rails/generators/rails/task/templates/task.rb +8 -0
- data/lib/rails/generators/resource_helpers.rb +3 -3
- data/lib/rails/generators/test_unit/integration/templates/integration_test.rb +0 -2
- data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb +4 -4
- data/lib/rails/paths.rb +11 -38
- data/lib/rails/rack/debugger.rb +3 -4
- data/lib/rails/rack/logger.rb +26 -12
- data/lib/rails/railtie.rb +6 -1
- data/lib/rails/railtie/configuration.rb +12 -5
- data/lib/rails/source_annotation_extractor.rb +12 -10
- data/lib/rails/tasks/documentation.rake +3 -1
- data/lib/rails/tasks/engine.rake +1 -0
- data/lib/rails/tasks/misc.rake +1 -1
- data/lib/rails/tasks/routes.rake +3 -23
- data/lib/rails/test_help.rb +1 -2
- data/lib/rails/test_unit/testing.rake +8 -4
- data/lib/rails/version.rb +3 -3
- metadata +131 -61
- checksums.yaml +0 -7
- data/lib/rails/generators/rails/plugin/USAGE +0 -13
- data/lib/rails/generators/rails/plugin/plugin_generator.rb +0 -54
- data/lib/rails/generators/rails/plugin/templates/MIT-LICENSE.tt +0 -20
- data/lib/rails/generators/rails/plugin/templates/README.tt +0 -13
- data/lib/rails/generators/rails/plugin/templates/Rakefile.tt +0 -23
- data/lib/rails/generators/rails/plugin/templates/init.rb +0 -1
- data/lib/rails/generators/rails/plugin/templates/install.rb +0 -1
- data/lib/rails/generators/rails/plugin/templates/lib/%file_name%.rb.tt +0 -1
- data/lib/rails/generators/rails/plugin/templates/lib/tasks/%file_name%_tasks.rake.tt +0 -4
- data/lib/rails/generators/rails/plugin/templates/uninstall.rb +0 -1
@@ -24,12 +24,21 @@ module Rails
|
|
24
24
|
initializer :initialize_logger, :group => :all do
|
25
25
|
Rails.logger ||= config.logger || begin
|
26
26
|
path = config.paths["log"].first
|
27
|
-
|
27
|
+
unless File.exist? File.dirname path
|
28
|
+
FileUtils.mkdir_p File.dirname path
|
29
|
+
end
|
30
|
+
|
31
|
+
f = File.open path, 'w'
|
32
|
+
f.binmode
|
33
|
+
f.sync = !Rails.env.production? # make sure every write flushes
|
34
|
+
|
35
|
+
logger = ActiveSupport::TaggedLogging.new(
|
36
|
+
ActiveSupport::BufferedLogger.new(f)
|
37
|
+
)
|
28
38
|
logger.level = ActiveSupport::BufferedLogger.const_get(config.log_level.to_s.upcase)
|
29
|
-
logger.auto_flushing = false if Rails.env.production?
|
30
39
|
logger
|
31
40
|
rescue StandardError
|
32
|
-
logger = ActiveSupport::BufferedLogger.new(STDERR)
|
41
|
+
logger = ActiveSupport::TaggedLogging.new(ActiveSupport::BufferedLogger.new(STDERR))
|
33
42
|
logger.level = ActiveSupport::BufferedLogger::WARN
|
34
43
|
logger.warn(
|
35
44
|
"Rails Error: Unable to access log file. Please ensure that #{path} exists and is chmod 0666. " +
|
@@ -37,7 +46,6 @@ module Rails
|
|
37
46
|
)
|
38
47
|
logger
|
39
48
|
end
|
40
|
-
at_exit { Rails.logger.flush if Rails.logger.respond_to?(:flush) }
|
41
49
|
end
|
42
50
|
|
43
51
|
# Initialize cache early in the stack so railties can make use of it.
|
@@ -51,13 +59,6 @@ module Rails
|
|
51
59
|
end
|
52
60
|
end
|
53
61
|
|
54
|
-
initializer :set_clear_dependencies_hook, :group => :all do
|
55
|
-
ActionDispatch::Reloader.to_cleanup do
|
56
|
-
ActiveSupport::DescendantsTracker.clear
|
57
|
-
ActiveSupport::Dependencies.clear
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
62
|
# Sets the dependency loading mechanism.
|
62
63
|
# TODO: Remove files from the $" and always use require.
|
63
64
|
initializer :initialize_dependency_mechanism, :group => :all do
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'active_support/core_ext/string/encoding'
|
2
2
|
require 'active_support/core_ext/kernel/reporting'
|
3
|
+
require 'active_support/file_update_checker'
|
3
4
|
require 'rails/engine/configuration'
|
4
5
|
|
5
6
|
module Rails
|
@@ -7,11 +8,11 @@ module Rails
|
|
7
8
|
class Configuration < ::Rails::Engine::Configuration
|
8
9
|
attr_accessor :allow_concurrency, :asset_host, :asset_path, :assets,
|
9
10
|
:cache_classes, :cache_store, :consider_all_requests_local,
|
10
|
-
:dependency_loading, :filter_parameters,
|
11
|
-
:force_ssl, :helpers_paths, :logger, :preload_frameworks,
|
12
|
-
:
|
13
|
-
:ssl_options, :static_cache_control, :session_options,
|
14
|
-
:time_zone, :whiny_nils
|
11
|
+
:dependency_loading, :exceptions_app, :file_watcher, :filter_parameters,
|
12
|
+
:force_ssl, :helpers_paths, :logger, :log_tags, :preload_frameworks,
|
13
|
+
:railties_order, :relative_url_root, :reload_plugins, :secret_token,
|
14
|
+
:serve_static_assets, :ssl_options, :static_cache_control, :session_options,
|
15
|
+
:time_zone, :reload_classes_only_on_change, :whiny_nils
|
15
16
|
|
16
17
|
attr_writer :log_level
|
17
18
|
attr_reader :encoding
|
@@ -19,22 +20,27 @@ module Rails
|
|
19
20
|
def initialize(*)
|
20
21
|
super
|
21
22
|
self.encoding = "utf-8"
|
22
|
-
@allow_concurrency
|
23
|
-
@consider_all_requests_local
|
24
|
-
@filter_parameters
|
25
|
-
@helpers_paths
|
26
|
-
@dependency_loading
|
27
|
-
@serve_static_assets
|
28
|
-
@static_cache_control
|
29
|
-
@force_ssl
|
30
|
-
@ssl_options
|
31
|
-
@session_store
|
32
|
-
@session_options
|
33
|
-
@time_zone
|
34
|
-
@log_level
|
35
|
-
@middleware
|
36
|
-
@generators
|
37
|
-
@cache_store
|
23
|
+
@allow_concurrency = false
|
24
|
+
@consider_all_requests_local = false
|
25
|
+
@filter_parameters = []
|
26
|
+
@helpers_paths = []
|
27
|
+
@dependency_loading = true
|
28
|
+
@serve_static_assets = true
|
29
|
+
@static_cache_control = nil
|
30
|
+
@force_ssl = false
|
31
|
+
@ssl_options = {}
|
32
|
+
@session_store = :cookie_store
|
33
|
+
@session_options = {}
|
34
|
+
@time_zone = "UTC"
|
35
|
+
@log_level = nil
|
36
|
+
@middleware = app_middleware
|
37
|
+
@generators = app_generators
|
38
|
+
@cache_store = [ :file_store, "#{root}/tmp/cache/" ]
|
39
|
+
@railties_order = [:all]
|
40
|
+
@relative_url_root = ENV["RAILS_RELATIVE_URL_ROOT"]
|
41
|
+
@reload_classes_only_on_change = true
|
42
|
+
@file_watcher = ActiveSupport::FileUpdateChecker
|
43
|
+
@exceptions_app = nil
|
38
44
|
|
39
45
|
@assets = ActiveSupport::OrderedOptions.new
|
40
46
|
@assets.enabled = false
|
@@ -2,6 +2,7 @@ module Rails
|
|
2
2
|
class Application
|
3
3
|
module Finisher
|
4
4
|
include Initializable
|
5
|
+
$rails_rake_task = nil
|
5
6
|
|
6
7
|
initializer :add_generator_templates do
|
7
8
|
config.generators.templates.unshift(*paths["lib/templates"].existent)
|
@@ -19,12 +20,6 @@ module Rails
|
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
22
|
-
initializer :add_to_prepare_blocks do
|
23
|
-
config.to_prepare_blocks.each do |block|
|
24
|
-
ActionDispatch::Reloader.to_prepare(&block)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
23
|
initializer :add_builtin_route do |app|
|
29
24
|
if Rails.env.development?
|
30
25
|
app.routes.append do
|
@@ -37,14 +32,22 @@ module Rails
|
|
37
32
|
build_middleware_stack
|
38
33
|
end
|
39
34
|
|
40
|
-
initializer :run_prepare_callbacks do
|
41
|
-
ActionDispatch::Reloader.prepare!
|
42
|
-
end
|
43
|
-
|
44
35
|
initializer :define_main_app_helper do |app|
|
45
36
|
app.routes.define_mounted_helper(:main_app)
|
46
37
|
end
|
47
38
|
|
39
|
+
initializer :add_to_prepare_blocks do
|
40
|
+
config.to_prepare_blocks.each do |block|
|
41
|
+
ActionDispatch::Reloader.to_prepare(&block)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# This needs to happen before eager load so it happens
|
46
|
+
# in exactly the same point regardless of config.cache_classes
|
47
|
+
initializer :run_prepare_callbacks do
|
48
|
+
ActionDispatch::Reloader.prepare!
|
49
|
+
end
|
50
|
+
|
48
51
|
initializer :eager_load! do
|
49
52
|
if config.cache_classes && !$rails_rake_task
|
50
53
|
ActiveSupport.run_load_hooks(:before_eager_load, self)
|
@@ -52,17 +55,37 @@ module Rails
|
|
52
55
|
end
|
53
56
|
end
|
54
57
|
|
58
|
+
# All initialization is done, including eager loading in production
|
55
59
|
initializer :finisher_hook do
|
56
60
|
ActiveSupport.run_load_hooks(:after_initialize, self)
|
57
61
|
end
|
58
62
|
|
59
|
-
#
|
60
|
-
#
|
61
|
-
|
62
|
-
|
63
|
-
reloader
|
64
|
-
reloader
|
65
|
-
ActionDispatch::Reloader.to_prepare
|
63
|
+
# Set app reload just after the finisher hook to ensure
|
64
|
+
# routes added in the hook are still loaded.
|
65
|
+
initializer :set_routes_reloader_hook do
|
66
|
+
reloader = routes_reloader
|
67
|
+
reloader.execute_if_updated
|
68
|
+
self.reloaders << reloader
|
69
|
+
ActionDispatch::Reloader.to_prepare { reloader.execute_if_updated }
|
70
|
+
end
|
71
|
+
|
72
|
+
# Set app reload just after the finisher hook to ensure
|
73
|
+
# paths added in the hook are still loaded.
|
74
|
+
initializer :set_clear_dependencies_hook, :group => :all do
|
75
|
+
callback = lambda do
|
76
|
+
ActiveSupport::DescendantsTracker.clear
|
77
|
+
ActiveSupport::Dependencies.clear
|
78
|
+
end
|
79
|
+
|
80
|
+
if config.reload_classes_only_on_change
|
81
|
+
reloader = config.file_watcher.new(*watchable_args, &callback)
|
82
|
+
self.reloaders << reloader
|
83
|
+
# We need to set a to_prepare callback regardless of the reloader result, i.e.
|
84
|
+
# models should be reloaded if any of the reloaders (i18n, routes) were updated.
|
85
|
+
ActionDispatch::Reloader.to_prepare(:prepend => true){ reloader.execute }
|
86
|
+
else
|
87
|
+
ActionDispatch::Reloader.to_cleanup(&callback)
|
88
|
+
end
|
66
89
|
end
|
67
90
|
|
68
91
|
# Disable dependency loading during request cycle
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Rails
|
2
|
+
class Application
|
3
|
+
##
|
4
|
+
# This class is just used for displaying route information when someone
|
5
|
+
# executes `rake routes`. People should not use this class.
|
6
|
+
class RouteInspector # :nodoc:
|
7
|
+
def initialize
|
8
|
+
@engines = ActiveSupport::OrderedHash.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def format all_routes, filter = nil
|
12
|
+
if filter
|
13
|
+
all_routes = all_routes.select{ |route| route.defaults[:controller] == filter }
|
14
|
+
end
|
15
|
+
|
16
|
+
routes = collect_routes(all_routes)
|
17
|
+
|
18
|
+
formatted_routes(routes) +
|
19
|
+
formatted_routes_for_engines
|
20
|
+
end
|
21
|
+
|
22
|
+
def collect_routes(routes)
|
23
|
+
routes = routes.collect do |route|
|
24
|
+
route_reqs = route.requirements
|
25
|
+
|
26
|
+
rack_app = route.app unless route.app.class.name.to_s =~ /^ActionDispatch::Routing/
|
27
|
+
|
28
|
+
controller = route_reqs[:controller] || ':controller'
|
29
|
+
action = route_reqs[:action] || ':action'
|
30
|
+
|
31
|
+
endpoint = rack_app ? rack_app.inspect : "#{controller}##{action}"
|
32
|
+
constraints = route_reqs.except(:controller, :action)
|
33
|
+
|
34
|
+
reqs = endpoint
|
35
|
+
reqs += " #{constraints.inspect}" unless constraints.empty?
|
36
|
+
|
37
|
+
verb = route.verb.source.gsub(/[$^]/, '')
|
38
|
+
|
39
|
+
collect_engine_routes(reqs, rack_app)
|
40
|
+
|
41
|
+
{:name => route.name.to_s, :verb => verb, :path => route.path.spec.to_s, :reqs => reqs }
|
42
|
+
end
|
43
|
+
|
44
|
+
# Skip the route if it's internal info route
|
45
|
+
routes.reject { |r| r[:path] =~ %r{/rails/info/properties|^/assets} }
|
46
|
+
end
|
47
|
+
|
48
|
+
def collect_engine_routes(name, rack_app)
|
49
|
+
return unless rack_app && rack_app.respond_to?(:routes)
|
50
|
+
return if @engines[name]
|
51
|
+
|
52
|
+
routes = rack_app.routes
|
53
|
+
if routes.is_a?(ActionDispatch::Routing::RouteSet)
|
54
|
+
@engines[name] = collect_routes(routes.routes)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def formatted_routes_for_engines
|
59
|
+
@engines.map do |name, routes|
|
60
|
+
["\nRoutes for #{name}:"] + formatted_routes(routes)
|
61
|
+
end.flatten
|
62
|
+
end
|
63
|
+
|
64
|
+
def formatted_routes(routes)
|
65
|
+
name_width = routes.map{ |r| r[:name].length }.max
|
66
|
+
verb_width = routes.map{ |r| r[:verb].length }.max
|
67
|
+
path_width = routes.map{ |r| r[:path].length }.max
|
68
|
+
|
69
|
+
routes.map do |r|
|
70
|
+
"#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:path].ljust(path_width)} #{r[:reqs]}"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -1,10 +1,13 @@
|
|
1
|
+
require "active_support/core_ext/module/delegation"
|
2
|
+
|
1
3
|
module Rails
|
2
4
|
class Application
|
3
|
-
class RoutesReloader
|
4
|
-
attr_reader :route_sets
|
5
|
+
class RoutesReloader
|
6
|
+
attr_reader :route_sets, :paths
|
7
|
+
delegate :execute_if_updated, :execute, :updated?, :to => :updater
|
5
8
|
|
6
9
|
def initialize
|
7
|
-
|
10
|
+
@paths = []
|
8
11
|
@route_sets = []
|
9
12
|
end
|
10
13
|
|
@@ -16,7 +19,15 @@ module Rails
|
|
16
19
|
revert
|
17
20
|
end
|
18
21
|
|
19
|
-
|
22
|
+
private
|
23
|
+
|
24
|
+
def updater
|
25
|
+
@updater ||= begin
|
26
|
+
updater = ActiveSupport::FileUpdateChecker.new(paths) { reload! }
|
27
|
+
updater.execute
|
28
|
+
updater
|
29
|
+
end
|
30
|
+
end
|
20
31
|
|
21
32
|
def clear!
|
22
33
|
route_sets.each do |routes|
|
@@ -30,7 +30,7 @@ class CodeStatistics #:nodoc:
|
|
30
30
|
stats = { "lines" => 0, "codelines" => 0, "classes" => 0, "methods" => 0 }
|
31
31
|
|
32
32
|
Dir.foreach(directory) do |file_name|
|
33
|
-
if File.
|
33
|
+
if File.directory?(directory + "/" + file_name) and (/^\./ !~ file_name)
|
34
34
|
newstats = calculate_directory_statistics(directory + "/" + file_name, pattern)
|
35
35
|
stats.each { |k, v| stats[k] += newstats[k] }
|
36
36
|
end
|
@@ -38,11 +38,22 @@ class CodeStatistics #:nodoc:
|
|
38
38
|
next unless file_name =~ pattern
|
39
39
|
|
40
40
|
f = File.open(directory + "/" + file_name)
|
41
|
-
|
41
|
+
comment_started = false
|
42
42
|
while line = f.gets
|
43
43
|
stats["lines"] += 1
|
44
|
-
|
45
|
-
|
44
|
+
if(comment_started)
|
45
|
+
if line =~ /^=end/
|
46
|
+
comment_started = false
|
47
|
+
end
|
48
|
+
next
|
49
|
+
else
|
50
|
+
if line =~ /^=begin/
|
51
|
+
comment_started = true
|
52
|
+
next
|
53
|
+
end
|
54
|
+
end
|
55
|
+
stats["classes"] += 1 if line =~ /^\s*class\s+[_A-Z]/
|
56
|
+
stats["methods"] += 1 if line =~ /^\s*def\s+[_a-z]/
|
46
57
|
stats["codelines"] += 1 unless line =~ /^\s*$/ || line =~ /^\s*#/
|
47
58
|
end
|
48
59
|
end
|
@@ -104,4 +115,4 @@ class CodeStatistics #:nodoc:
|
|
104
115
|
puts " Code LOC: #{code} Test LOC: #{tests} Code to Test Ratio: 1:#{sprintf("%.1f", tests.to_f/code)}"
|
105
116
|
puts ""
|
106
117
|
end
|
107
|
-
|
118
|
+
end
|
data/lib/rails/commands.rb
CHANGED
@@ -4,6 +4,7 @@ ARGV << '--help' if ARGV.empty?
|
|
4
4
|
|
5
5
|
aliases = {
|
6
6
|
"g" => "generate",
|
7
|
+
"d" => "destroy",
|
7
8
|
"c" => "console",
|
8
9
|
"s" => "server",
|
9
10
|
"db" => "dbconsole",
|
@@ -15,15 +16,15 @@ command = aliases[command] || command
|
|
15
16
|
|
16
17
|
case command
|
17
18
|
when 'generate', 'destroy', 'plugin'
|
19
|
+
require 'rails/generators'
|
20
|
+
|
18
21
|
if command == 'plugin' && ARGV.first == 'new'
|
19
22
|
require "rails/commands/plugin_new"
|
20
23
|
else
|
21
24
|
require APP_PATH
|
22
25
|
Rails.application.require_environment!
|
23
26
|
|
24
|
-
|
25
|
-
Rails.application = engine
|
26
|
-
end
|
27
|
+
Rails.application.load_generators
|
27
28
|
|
28
29
|
require "rails/commands/#{command}"
|
29
30
|
end
|
@@ -87,13 +88,13 @@ The most common rails commands are:
|
|
87
88
|
|
88
89
|
In addition to those, there are:
|
89
90
|
application Generate the Rails application code
|
90
|
-
destroy Undo code generated with "generate"
|
91
|
+
destroy Undo code generated with "generate" (short-cut alias: "d")
|
91
92
|
benchmarker See how fast a piece of code runs
|
92
93
|
profiler Get profile information from a piece of code
|
93
94
|
plugin Install a plugin
|
94
95
|
runner Run a piece of code in the application environment (short-cut alias: "r")
|
95
96
|
|
96
|
-
All commands can be run with -h for more information.
|
97
|
+
All commands can be run with -h (or --help) for more information.
|
97
98
|
EOT
|
98
99
|
exit(1)
|
99
100
|
end
|
@@ -9,10 +9,17 @@ if ARGV.first != "new"
|
|
9
9
|
ARGV[0] = "--help"
|
10
10
|
else
|
11
11
|
ARGV.shift
|
12
|
+
railsrc = File.join(File.expand_path("~"), ".railsrc")
|
13
|
+
if File.exist?(railsrc)
|
14
|
+
extra_args_string = File.open(railsrc).read
|
15
|
+
extra_args = extra_args_string.split(/\n+/).map {|l| l.split}.flatten
|
16
|
+
puts "Using #{extra_args.join(" ")} from #{railsrc}"
|
17
|
+
ARGV << extra_args
|
18
|
+
ARGV.flatten!
|
19
|
+
end
|
12
20
|
end
|
13
21
|
|
14
22
|
require 'rubygems' if ARGV.include?("--dev")
|
15
|
-
|
16
23
|
require 'rails/generators'
|
17
24
|
require 'rails/generators/rails/app/app_generator'
|
18
25
|
|
@@ -33,7 +33,7 @@ module Rails
|
|
33
33
|
options['mode'] = mode
|
34
34
|
end
|
35
35
|
|
36
|
-
opt.on("
|
36
|
+
opt.on("--header") do |h|
|
37
37
|
options['header'] = h
|
38
38
|
end
|
39
39
|
|
@@ -41,7 +41,7 @@ module Rails
|
|
41
41
|
abort opt.to_s unless (0..1).include?(ARGV.size)
|
42
42
|
end
|
43
43
|
|
44
|
-
unless config =
|
44
|
+
unless config = @app.config.database_configuration[Rails.env]
|
45
45
|
abort "No database is configured for the environment '#{Rails.env}'"
|
46
46
|
end
|
47
47
|
|