railties 5.0.7.2 → 5.1.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +77 -567
- data/MIT-LICENSE +1 -1
- data/RDOC_MAIN.rdoc +3 -3
- data/README.rdoc +1 -1
- data/exe/rails +2 -2
- data/lib/rails.rb +18 -18
- data/lib/rails/all.rb +1 -1
- data/lib/rails/api/generator.rb +28 -0
- data/lib/rails/api/task.rb +54 -42
- data/lib/rails/app_loader.rb +9 -9
- data/lib/rails/application.rb +30 -35
- data/lib/rails/application/bootstrap.rb +13 -7
- data/lib/rails/application/configuration.rb +30 -53
- data/lib/rails/application/default_middleware_stack.rb +3 -5
- data/lib/rails/application/finisher.rb +16 -7
- data/lib/rails/application/routes_reloader.rb +16 -1
- data/lib/rails/application_controller.rb +10 -10
- data/lib/rails/backtrace_cleaner.rb +5 -5
- data/lib/rails/cli.rb +7 -5
- data/lib/rails/code_statistics.rb +16 -17
- data/lib/rails/code_statistics_calculator.rb +3 -3
- data/lib/rails/command.rb +111 -0
- data/lib/rails/command/actions.rb +42 -0
- data/lib/rails/command/base.rb +149 -0
- data/lib/rails/command/behavior.rb +123 -0
- data/lib/rails/command/environment_argument.rb +34 -0
- data/lib/rails/commands.rb +2 -4
- data/lib/rails/commands/application/application_command.rb +29 -0
- data/lib/rails/commands/console/console_command.rb +89 -0
- data/lib/rails/commands/dbconsole/dbconsole_command.rb +155 -0
- data/lib/rails/commands/destroy/destroy_command.rb +21 -0
- data/lib/rails/commands/generate/generate_command.rb +23 -0
- data/lib/rails/commands/help/USAGE +15 -0
- data/lib/rails/commands/help/help_command.rb +13 -0
- data/lib/rails/commands/new/new_command.rb +15 -0
- data/lib/rails/commands/plugin/plugin_command.rb +43 -0
- data/lib/rails/commands/rake/rake_command.rb +49 -0
- data/lib/rails/commands/runner/USAGE +17 -0
- data/lib/rails/commands/runner/runner_command.rb +46 -0
- data/lib/rails/commands/secrets/USAGE +52 -0
- data/lib/rails/commands/secrets/secrets_command.rb +36 -0
- data/lib/rails/commands/server/server_command.rb +177 -0
- data/lib/rails/commands/test/test_command.rb +20 -0
- data/lib/rails/commands/version/version_command.rb +9 -0
- data/lib/rails/configuration.rb +7 -7
- data/lib/rails/console/app.rb +4 -4
- data/lib/rails/dev_caching.rb +8 -8
- data/lib/rails/engine.rb +62 -63
- data/lib/rails/engine/commands.rb +6 -13
- data/lib/rails/engine/configuration.rb +2 -2
- data/lib/rails/gem_version.rb +3 -3
- data/lib/rails/generators.rb +229 -313
- data/lib/rails/generators/actions.rb +20 -21
- data/lib/rails/generators/actions/create_migration.rb +24 -25
- data/lib/rails/generators/active_model.rb +3 -3
- data/lib/rails/generators/app_base.rb +123 -93
- data/lib/rails/generators/base.rb +32 -33
- data/lib/rails/generators/css/assets/assets_generator.rb +1 -1
- data/lib/rails/generators/erb.rb +14 -14
- data/lib/rails/generators/erb/controller/controller_generator.rb +1 -1
- data/lib/rails/generators/erb/mailer/mailer_generator.rb +12 -12
- data/lib/rails/generators/erb/scaffold/scaffold_generator.rb +3 -3
- data/lib/rails/generators/generated_attribute.rb +27 -27
- data/lib/rails/generators/js/assets/assets_generator.rb +1 -1
- data/lib/rails/generators/migration.rb +8 -8
- data/lib/rails/generators/model_helpers.rb +2 -2
- data/lib/rails/generators/named_base.rb +56 -56
- data/lib/rails/generators/rails/app/app_generator.rb +98 -81
- data/lib/rails/generators/rails/app/templates/Gemfile +7 -2
- data/lib/rails/generators/rails/app/templates/app/assets/config/manifest.js.tt +0 -2
- data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +6 -4
- data/lib/rails/generators/rails/app/templates/app/assets/javascripts/cable.js +1 -1
- data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +2 -2
- data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/bin/{setup → setup.tt} +6 -0
- data/lib/rails/generators/rails/app/templates/bin/{update → update.tt} +2 -1
- data/lib/rails/generators/rails/app/templates/bin/yarn +9 -0
- data/lib/rails/generators/rails/app/templates/config/cable.yml +1 -0
- data/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml +1 -0
- data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml +1 -0
- data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml +1 -0
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml +2 -1
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml +1 -0
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml +1 -0
- data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml +2 -2
- data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml +1 -0
- data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml +1 -1
- data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml +1 -1
- data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +1 -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 +1 -1
- data/lib/rails/generators/rails/app/templates/config/initializers/application_controller_renderer.rb +4 -6
- data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +8 -3
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults.rb.tt +6 -5
- data/lib/rails/generators/rails/app/templates/config/locales/en.yml +10 -0
- data/lib/rails/generators/rails/app/templates/config/puma.rb +16 -7
- data/lib/rails/generators/rails/app/templates/config/secrets.yml +12 -2
- data/lib/rails/generators/rails/app/templates/gitignore +5 -1
- data/lib/rails/generators/rails/app/templates/package.json +5 -0
- data/lib/rails/generators/rails/app/templates/public/404.html +6 -6
- data/lib/rails/generators/rails/app/templates/public/422.html +6 -6
- data/lib/rails/generators/rails/app/templates/public/500.html +6 -6
- data/lib/rails/generators/rails/app/templates/public/robots.txt +0 -4
- data/lib/rails/generators/rails/app/templates/test/application_system_test_case.rb +5 -0
- data/lib/rails/generators/rails/app/templates/test/test_helper.rb +0 -1
- data/lib/rails/generators/rails/assets/assets_generator.rb +10 -10
- data/lib/rails/generators/rails/controller/controller_generator.rb +15 -12
- data/lib/rails/generators/rails/encrypted_secrets/encrypted_secrets_generator.rb +66 -0
- data/lib/rails/generators/rails/encrypted_secrets/templates/config/secrets.yml.enc +3 -0
- data/lib/rails/generators/rails/generator/generator_generator.rb +2 -3
- data/lib/rails/generators/rails/helper/helper_generator.rb +1 -1
- data/lib/rails/generators/rails/model/model_generator.rb +1 -1
- data/lib/rails/generators/rails/plugin/plugin_generator.rb +21 -26
- data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +1 -0
- data/lib/rails/generators/rails/plugin/templates/bin/test.tt +3 -9
- data/lib/rails/generators/rails/plugin/templates/test/application_system_test_case.rb +5 -0
- data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb +0 -3
- data/lib/rails/generators/rails/resource/resource_generator.rb +2 -2
- data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +5 -1
- data/lib/rails/generators/rails/scaffold/templates/scaffold.css +4 -8
- data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +2 -3
- data/lib/rails/generators/rails/system_test/USAGE +10 -0
- data/lib/rails/generators/rails/system_test/system_test_generator.rb +7 -0
- data/lib/rails/generators/rails/task/task_generator.rb +1 -2
- data/lib/rails/generators/resource_helpers.rb +13 -10
- data/lib/rails/generators/test_case.rb +5 -6
- data/lib/rails/generators/test_unit.rb +1 -1
- data/lib/rails/generators/test_unit/controller/controller_generator.rb +3 -3
- data/lib/rails/generators/test_unit/generator/generator_generator.rb +3 -3
- data/lib/rails/generators/test_unit/helper/helper_generator.rb +1 -1
- data/lib/rails/generators/test_unit/integration/integration_generator.rb +2 -2
- data/lib/rails/generators/test_unit/job/job_generator.rb +3 -3
- data/lib/rails/generators/test_unit/mailer/mailer_generator.rb +5 -5
- data/lib/rails/generators/test_unit/model/model_generator.rb +3 -4
- data/lib/rails/generators/test_unit/plugin/plugin_generator.rb +2 -2
- data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +3 -3
- data/lib/rails/generators/test_unit/system/system_generator.rb +17 -0
- data/lib/rails/generators/test_unit/system/templates/application_system_test_case.rb +5 -0
- data/lib/rails/generators/test_unit/system/templates/system_test.rb +9 -0
- data/lib/rails/generators/testing/assertions.rb +4 -4
- data/lib/rails/generators/testing/behaviour.rb +20 -21
- data/lib/rails/info.rb +20 -20
- data/lib/rails/info_controller.rb +15 -15
- data/lib/rails/initializable.rb +6 -2
- data/lib/rails/mailers_controller.rb +11 -11
- data/lib/rails/paths.rb +4 -5
- data/lib/rails/plugin/test.rb +7 -0
- data/lib/rails/rack/logger.rb +44 -46
- data/lib/rails/railtie.rb +41 -38
- data/lib/rails/railtie/configurable.rb +6 -6
- data/lib/rails/railtie/configuration.rb +1 -1
- data/lib/rails/ruby_version_check.rb +1 -1
- data/lib/rails/secrets.rb +111 -0
- data/lib/rails/source_annotation_extractor.rb +15 -9
- data/lib/rails/tasks.rb +3 -2
- data/lib/rails/tasks/annotations.rake +3 -3
- data/lib/rails/tasks/dev.rake +2 -2
- data/lib/rails/tasks/engine.rake +4 -4
- data/lib/rails/tasks/framework.rake +4 -18
- data/lib/rails/tasks/initializers.rake +1 -1
- data/lib/rails/tasks/log.rake +14 -10
- data/lib/rails/tasks/middleware.rake +1 -1
- data/lib/rails/tasks/misc.rake +10 -10
- data/lib/rails/tasks/restart.rake +4 -4
- data/lib/rails/tasks/routes.rake +3 -12
- data/lib/rails/tasks/statistics.rake +3 -3
- data/lib/rails/tasks/tmp.rake +7 -7
- data/lib/rails/tasks/yarn.rake +11 -0
- data/lib/rails/templates/rails/mailers/email.html.erb +4 -1
- data/lib/rails/test_help.rb +28 -10
- data/lib/rails/test_unit/line_filtering.rb +69 -3
- data/lib/rails/test_unit/minitest_plugin.rb +139 -0
- data/lib/rails/test_unit/railtie.rb +2 -1
- data/lib/rails/test_unit/reporter.rb +3 -8
- data/lib/rails/test_unit/test_requirer.rb +28 -0
- data/lib/rails/test_unit/testing.rake +19 -14
- data/lib/rails/version.rb +1 -1
- data/lib/rails/welcome_controller.rb +1 -1
- metadata +53 -30
- data/lib/minitest/rails_plugin.rb +0 -49
- data/lib/rails/commands/application.rb +0 -17
- data/lib/rails/commands/commands_tasks.rb +0 -180
- data/lib/rails/commands/console.rb +0 -68
- data/lib/rails/commands/console_helper.rb +0 -34
- data/lib/rails/commands/dbconsole.rb +0 -173
- data/lib/rails/commands/destroy.rb +0 -11
- data/lib/rails/commands/generate.rb +0 -13
- data/lib/rails/commands/plugin.rb +0 -23
- data/lib/rails/commands/rake_proxy.rb +0 -41
- data/lib/rails/commands/runner.rb +0 -71
- data/lib/rails/commands/server.rb +0 -163
- data/lib/rails/commands/test.rb +0 -10
- data/lib/rails/engine/commands_tasks.rb +0 -118
- data/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +0 -3
- data/lib/rails/rack/debugger.rb +0 -3
- data/lib/rails/test_unit/runner.rb +0 -141
data/lib/rails/console/app.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "active_support/all"
|
2
|
+
require "action_controller"
|
3
3
|
|
4
4
|
module Rails
|
5
5
|
module ConsoleMethods
|
6
6
|
# reference the global "app" instance, created on demand. To recreate the
|
7
7
|
# instance, pass a non-false value as the parameter.
|
8
|
-
def app(create=false)
|
8
|
+
def app(create = false)
|
9
9
|
@app_integration_instance = nil if create
|
10
10
|
@app_integration_instance ||= new_session do |sess|
|
11
11
|
sess.host! "www.example.com"
|
@@ -27,7 +27,7 @@ module Rails
|
|
27
27
|
end
|
28
28
|
|
29
29
|
# reloads the environment
|
30
|
-
def reload!(print=true)
|
30
|
+
def reload!(print = true)
|
31
31
|
puts "Reloading..." if print
|
32
32
|
Rails.application.reloader.reload!
|
33
33
|
true
|
data/lib/rails/dev_caching.rb
CHANGED
@@ -1,27 +1,27 @@
|
|
1
|
-
require
|
1
|
+
require "fileutils"
|
2
2
|
|
3
3
|
module Rails
|
4
4
|
module DevCaching # :nodoc:
|
5
5
|
class << self
|
6
|
-
FILE =
|
6
|
+
FILE = "tmp/caching-dev.txt"
|
7
7
|
|
8
8
|
def enable_by_file
|
9
|
-
FileUtils.mkdir_p(
|
9
|
+
FileUtils.mkdir_p("tmp")
|
10
10
|
|
11
11
|
if File.exist?(FILE)
|
12
12
|
delete_cache_file
|
13
|
-
puts
|
13
|
+
puts "Development mode is no longer being cached."
|
14
14
|
else
|
15
15
|
create_cache_file
|
16
|
-
puts
|
16
|
+
puts "Development mode is now being cached."
|
17
17
|
end
|
18
18
|
|
19
|
-
FileUtils.touch
|
20
|
-
FileUtils.rm_f(
|
19
|
+
FileUtils.touch "tmp/restart.txt"
|
20
|
+
FileUtils.rm_f("tmp/pids/server.pid")
|
21
21
|
end
|
22
22
|
|
23
23
|
def enable_by_argument(caching)
|
24
|
-
FileUtils.mkdir_p(
|
24
|
+
FileUtils.mkdir_p("tmp")
|
25
25
|
|
26
26
|
if caching
|
27
27
|
create_cache_file
|
data/lib/rails/engine.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
1
|
+
require "rails/railtie"
|
2
|
+
require "rails/engine/railties"
|
3
|
+
require "active_support/core_ext/module/delegation"
|
4
|
+
require "pathname"
|
5
|
+
require "thread"
|
6
6
|
|
7
7
|
module Rails
|
8
8
|
# <tt>Rails::Engine</tt> allows you to wrap a specific Rails application or subset of
|
@@ -109,7 +109,7 @@ module Rails
|
|
109
109
|
#
|
110
110
|
# == Endpoint
|
111
111
|
#
|
112
|
-
# An engine can also be a
|
112
|
+
# An engine can also be a Rack application. It can be useful if you have a Rack application that
|
113
113
|
# you would like to wrap with +Engine+ and provide with some of the +Engine+'s features.
|
114
114
|
#
|
115
115
|
# To do that, use the +endpoint+ method:
|
@@ -128,7 +128,7 @@ module Rails
|
|
128
128
|
#
|
129
129
|
# == Middleware stack
|
130
130
|
#
|
131
|
-
# As an engine can now be a
|
131
|
+
# As an engine can now be a Rack endpoint, it can also have a middleware
|
132
132
|
# stack. The usage is exactly the same as in <tt>Application</tt>:
|
133
133
|
#
|
134
134
|
# module MyEngine
|
@@ -337,7 +337,7 @@ module Rails
|
|
337
337
|
# == Loading priority
|
338
338
|
#
|
339
339
|
# In order to change engine's priority you can use +config.railties_order+ in the main application.
|
340
|
-
# It will affect the priority of loading views, helpers, assets and all the other files
|
340
|
+
# It will affect the priority of loading views, helpers, assets, and all the other files
|
341
341
|
# related to engine or application.
|
342
342
|
#
|
343
343
|
# # load Blog::Engine with highest priority, followed by application and other railties
|
@@ -380,7 +380,7 @@ module Rails
|
|
380
380
|
def isolate_namespace(mod)
|
381
381
|
engine_name(generate_railtie_name(mod.name))
|
382
382
|
|
383
|
-
|
383
|
+
routes.default_scope = { module: ActiveSupport::Inflector.underscore(mod.name) }
|
384
384
|
self.isolated = true
|
385
385
|
|
386
386
|
unless mod.respond_to?(:railtie_namespace)
|
@@ -402,7 +402,7 @@ module Rails
|
|
402
402
|
end
|
403
403
|
|
404
404
|
unless mod.respond_to?(:railtie_routes_url_helpers)
|
405
|
-
define_method(:railtie_routes_url_helpers) {|include_path_helpers = true| railtie.routes.url_helpers(include_path_helpers) }
|
405
|
+
define_method(:railtie_routes_url_helpers) { |include_path_helpers = true| railtie.routes.url_helpers(include_path_helpers) }
|
406
406
|
end
|
407
407
|
end
|
408
408
|
end
|
@@ -436,7 +436,7 @@ module Rails
|
|
436
436
|
|
437
437
|
# Load console and invoke the registered hooks.
|
438
438
|
# Check <tt>Rails::Railtie.console</tt> for more info.
|
439
|
-
def load_console(app=self)
|
439
|
+
def load_console(app = self)
|
440
440
|
require "rails/console/app"
|
441
441
|
require "rails/console/helpers"
|
442
442
|
run_console_blocks(app)
|
@@ -445,14 +445,14 @@ module Rails
|
|
445
445
|
|
446
446
|
# Load Rails runner and invoke the registered hooks.
|
447
447
|
# Check <tt>Rails::Railtie.runner</tt> for more info.
|
448
|
-
def load_runner(app=self)
|
448
|
+
def load_runner(app = self)
|
449
449
|
run_runner_blocks(app)
|
450
450
|
self
|
451
451
|
end
|
452
452
|
|
453
453
|
# Load Rake, railties tasks and invoke the registered hooks.
|
454
454
|
# Check <tt>Rails::Railtie.rake_tasks</tt> for more info.
|
455
|
-
def load_tasks(app=self)
|
455
|
+
def load_tasks(app = self)
|
456
456
|
require "rake"
|
457
457
|
run_tasks_blocks(app)
|
458
458
|
self
|
@@ -460,7 +460,7 @@ module Rails
|
|
460
460
|
|
461
461
|
# Load Rails generators and invoke the registered hooks.
|
462
462
|
# Check <tt>Rails::Railtie.generators</tt> for more info.
|
463
|
-
def load_generators(app=self)
|
463
|
+
def load_generators(app = self)
|
464
464
|
require "rails/generators"
|
465
465
|
run_generators_blocks(app)
|
466
466
|
Rails::Generators.configure!(app.config.generators)
|
@@ -499,7 +499,7 @@ module Rails
|
|
499
499
|
paths["app/helpers"].existent
|
500
500
|
end
|
501
501
|
|
502
|
-
# Returns the underlying
|
502
|
+
# Returns the underlying Rack application for this engine.
|
503
503
|
def app
|
504
504
|
@app || @app_build_lock.synchronize {
|
505
505
|
@app ||= begin
|
@@ -549,7 +549,7 @@ module Rails
|
|
549
549
|
load(seed_file) if seed_file
|
550
550
|
end
|
551
551
|
|
552
|
-
# Add configured load paths to
|
552
|
+
# Add configured load paths to Ruby's load path, and remove duplicate entries.
|
553
553
|
initializer :set_load_path, before: :bootstrap_hook do
|
554
554
|
_all_load_paths.reverse_each do |path|
|
555
555
|
$LOAD_PATH.unshift(path) if File.directory?(path)
|
@@ -573,7 +573,7 @@ module Rails
|
|
573
573
|
end
|
574
574
|
|
575
575
|
initializer :add_routing_paths do |app|
|
576
|
-
routing_paths =
|
576
|
+
routing_paths = paths["config/routes.rb"].existent
|
577
577
|
|
578
578
|
if routes? || routing_paths.any?
|
579
579
|
app.routes_reloader.paths.unshift(*routing_paths)
|
@@ -590,8 +590,8 @@ module Rails
|
|
590
590
|
initializer :add_view_paths do
|
591
591
|
views = paths["app/views"].existent
|
592
592
|
unless views.empty?
|
593
|
-
ActiveSupport.on_load(:action_controller){ prepend_view_path(views) if respond_to?(:prepend_view_path) }
|
594
|
-
ActiveSupport.on_load(:action_mailer){ prepend_view_path(views) }
|
593
|
+
ActiveSupport.on_load(:action_controller) { prepend_view_path(views) if respond_to?(:prepend_view_path) }
|
594
|
+
ActiveSupport.on_load(:action_mailer) { prepend_view_path(views) }
|
595
595
|
end
|
596
596
|
end
|
597
597
|
|
@@ -619,7 +619,7 @@ module Rails
|
|
619
619
|
end
|
620
620
|
|
621
621
|
rake_tasks do
|
622
|
-
next if
|
622
|
+
next if is_a?(Rails::Application)
|
623
623
|
next unless has_migrations?
|
624
624
|
|
625
625
|
namespace railtie_name do
|
@@ -643,62 +643,61 @@ module Rails
|
|
643
643
|
|
644
644
|
protected
|
645
645
|
|
646
|
-
|
647
|
-
|
648
|
-
load(
|
646
|
+
def run_tasks_blocks(*) #:nodoc:
|
647
|
+
super
|
648
|
+
paths["lib/tasks"].existent.sort.each { |ext| load(ext) }
|
649
649
|
end
|
650
|
-
end
|
651
650
|
|
652
|
-
|
653
|
-
super
|
654
|
-
paths["lib/tasks"].existent.sort.each { |ext| load(ext) }
|
655
|
-
end
|
656
|
-
|
657
|
-
def has_migrations? #:nodoc:
|
658
|
-
paths["db/migrate"].existent.any?
|
659
|
-
end
|
651
|
+
private
|
660
652
|
|
661
|
-
|
653
|
+
def load_config_initializer(initializer) # :doc:
|
654
|
+
ActiveSupport::Notifications.instrument("load_config_initializer.railties", initializer: initializer) do
|
655
|
+
load(initializer)
|
656
|
+
end
|
657
|
+
end
|
662
658
|
|
663
|
-
|
664
|
-
|
665
|
-
root_path = parent != root_path && parent
|
659
|
+
def has_migrations?
|
660
|
+
paths["db/migrate"].existent.any?
|
666
661
|
end
|
667
662
|
|
668
|
-
|
669
|
-
|
663
|
+
def self.find_root_with_flag(flag, root_path, default = nil) #:nodoc:
|
664
|
+
while root_path && File.directory?(root_path) && !File.exist?("#{root_path}/#{flag}")
|
665
|
+
parent = File.dirname(root_path)
|
666
|
+
root_path = parent != root_path && parent
|
667
|
+
end
|
670
668
|
|
671
|
-
|
672
|
-
|
669
|
+
root = File.exist?("#{root_path}/#{flag}") ? root_path : default
|
670
|
+
raise "Could not find root path for #{self}" unless root
|
673
671
|
|
674
|
-
|
675
|
-
|
676
|
-
end
|
672
|
+
Pathname.new File.realpath root
|
673
|
+
end
|
677
674
|
|
678
|
-
|
679
|
-
|
680
|
-
|
675
|
+
def default_middleware_stack
|
676
|
+
ActionDispatch::MiddlewareStack.new
|
677
|
+
end
|
681
678
|
|
682
|
-
|
683
|
-
|
684
|
-
|
679
|
+
def _all_autoload_once_paths
|
680
|
+
config.autoload_once_paths
|
681
|
+
end
|
685
682
|
|
686
|
-
|
687
|
-
|
688
|
-
|
683
|
+
def _all_autoload_paths
|
684
|
+
@_all_autoload_paths ||= (config.autoload_paths + config.eager_load_paths + config.autoload_once_paths).uniq
|
685
|
+
end
|
689
686
|
|
690
|
-
|
687
|
+
def _all_load_paths
|
688
|
+
@_all_load_paths ||= (config.paths.load_paths + _all_autoload_paths).uniq
|
689
|
+
end
|
691
690
|
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
691
|
+
def build_request(env)
|
692
|
+
env.merge!(env_config)
|
693
|
+
req = ActionDispatch::Request.new env
|
694
|
+
req.routes = routes
|
695
|
+
req.engine_script_name = req.script_name
|
696
|
+
req
|
697
|
+
end
|
699
698
|
|
700
|
-
|
701
|
-
|
702
|
-
|
699
|
+
def build_middleware
|
700
|
+
config.middleware
|
701
|
+
end
|
703
702
|
end
|
704
703
|
end
|
@@ -1,14 +1,7 @@
|
|
1
|
-
|
1
|
+
unless defined?(APP_PATH)
|
2
|
+
if File.exist?(File.expand_path("test/dummy/config/application.rb", ENGINE_ROOT))
|
3
|
+
APP_PATH = File.expand_path("test/dummy/config/application", ENGINE_ROOT)
|
4
|
+
end
|
5
|
+
end
|
2
6
|
|
3
|
-
|
4
|
-
|
5
|
-
aliases = {
|
6
|
-
"g" => "generate",
|
7
|
-
"d" => "destroy",
|
8
|
-
"t" => "test"
|
9
|
-
}
|
10
|
-
|
11
|
-
command = ARGV.shift
|
12
|
-
command = aliases[command] || command
|
13
|
-
|
14
|
-
Rails::Engine::CommandsTasks.new(ARGV).run_command!(command)
|
7
|
+
require "rails/commands"
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "rails/railtie/configuration"
|
2
2
|
|
3
3
|
module Rails
|
4
4
|
class Engine
|
@@ -7,7 +7,7 @@ module Rails
|
|
7
7
|
attr_accessor :middleware
|
8
8
|
attr_writer :eager_load_paths, :autoload_once_paths, :autoload_paths
|
9
9
|
|
10
|
-
def initialize(root=nil)
|
10
|
+
def initialize(root = nil)
|
11
11
|
super()
|
12
12
|
@root = root
|
13
13
|
@generators = app_generators.dup
|
data/lib/rails/gem_version.rb
CHANGED
data/lib/rails/generators.rb
CHANGED
@@ -1,45 +1,48 @@
|
|
1
|
-
activesupport_path = File.expand_path(
|
1
|
+
activesupport_path = File.expand_path("../../../../activesupport/lib", __FILE__)
|
2
2
|
$:.unshift(activesupport_path) if File.directory?(activesupport_path) && !$:.include?(activesupport_path)
|
3
3
|
|
4
|
-
require
|
4
|
+
require "thor/group"
|
5
|
+
require "rails/command"
|
5
6
|
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
7
|
+
require "active_support"
|
8
|
+
require "active_support/core_ext/object/blank"
|
9
|
+
require "active_support/core_ext/kernel/singleton_class"
|
10
|
+
require "active_support/core_ext/array/extract_options"
|
11
|
+
require "active_support/core_ext/hash/deep_merge"
|
12
|
+
require "active_support/core_ext/module/attribute_accessors"
|
13
|
+
require "active_support/core_ext/string/inflections"
|
13
14
|
|
14
15
|
module Rails
|
15
16
|
module Generators
|
16
|
-
|
17
|
-
|
18
|
-
autoload :
|
19
|
-
autoload :
|
20
|
-
autoload :
|
21
|
-
autoload :
|
22
|
-
autoload :
|
17
|
+
include Rails::Command::Behavior
|
18
|
+
|
19
|
+
autoload :Actions, "rails/generators/actions"
|
20
|
+
autoload :ActiveModel, "rails/generators/active_model"
|
21
|
+
autoload :Base, "rails/generators/base"
|
22
|
+
autoload :Migration, "rails/generators/migration"
|
23
|
+
autoload :NamedBase, "rails/generators/named_base"
|
24
|
+
autoload :ResourceHelpers, "rails/generators/resource_helpers"
|
25
|
+
autoload :TestCase, "rails/generators/test_case"
|
23
26
|
|
24
27
|
mattr_accessor :namespace
|
25
28
|
|
26
29
|
DEFAULT_ALIASES = {
|
27
30
|
rails: {
|
28
|
-
actions:
|
29
|
-
orm:
|
30
|
-
javascripts:
|
31
|
-
javascript_engine:
|
32
|
-
resource_controller:
|
33
|
-
scaffold_controller:
|
34
|
-
stylesheets:
|
35
|
-
stylesheet_engine:
|
36
|
-
scaffold_stylesheet:
|
37
|
-
template_engine:
|
38
|
-
test_framework:
|
31
|
+
actions: "-a",
|
32
|
+
orm: "-o",
|
33
|
+
javascripts: "-j",
|
34
|
+
javascript_engine: "-je",
|
35
|
+
resource_controller: "-c",
|
36
|
+
scaffold_controller: "-c",
|
37
|
+
stylesheets: "-y",
|
38
|
+
stylesheet_engine: "-se",
|
39
|
+
scaffold_stylesheet: "-ss",
|
40
|
+
template_engine: "-e",
|
41
|
+
test_framework: "-t"
|
39
42
|
},
|
40
43
|
|
41
44
|
test_unit: {
|
42
|
-
fixture_replacement:
|
45
|
+
fixture_replacement: "-r",
|
43
46
|
}
|
44
47
|
}
|
45
48
|
|
@@ -59,342 +62,255 @@ module Rails
|
|
59
62
|
stylesheets: true,
|
60
63
|
stylesheet_engine: :css,
|
61
64
|
scaffold_stylesheet: true,
|
62
|
-
|
65
|
+
system_tests: nil,
|
66
|
+
test_framework: false,
|
63
67
|
template_engine: :erb
|
64
68
|
}
|
65
69
|
}
|
66
70
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
def self.templates_path #:nodoc:
|
79
|
-
@templates_path ||= []
|
80
|
-
end
|
81
|
-
|
82
|
-
def self.aliases #:nodoc:
|
83
|
-
@aliases ||= DEFAULT_ALIASES.dup
|
84
|
-
end
|
85
|
-
|
86
|
-
def self.options #:nodoc:
|
87
|
-
@options ||= DEFAULT_OPTIONS.dup
|
88
|
-
end
|
89
|
-
|
90
|
-
# Hold configured generators fallbacks. If a plugin developer wants a
|
91
|
-
# generator group to fallback to another group in case of missing generators,
|
92
|
-
# they can add a fallback.
|
93
|
-
#
|
94
|
-
# For example, shoulda is considered a test_framework and is an extension
|
95
|
-
# of test_unit. However, most part of shoulda generators are similar to
|
96
|
-
# test_unit ones.
|
97
|
-
#
|
98
|
-
# Shoulda then can tell generators to search for test_unit generators when
|
99
|
-
# some of them are not available by adding a fallback:
|
100
|
-
#
|
101
|
-
# Rails::Generators.fallbacks[:shoulda] = :test_unit
|
102
|
-
def self.fallbacks
|
103
|
-
@fallbacks ||= {}
|
104
|
-
end
|
105
|
-
|
106
|
-
# Configure generators for API only applications. It basically hides
|
107
|
-
# everything that is usually browser related, such as assets and session
|
108
|
-
# migration generators, and completely disable helpers and assets
|
109
|
-
# so generators such as scaffold won't create them.
|
110
|
-
def self.api_only!
|
111
|
-
hide_namespaces "assets", "helper", "css", "js"
|
112
|
-
|
113
|
-
options[:rails].merge!(
|
114
|
-
api: true,
|
115
|
-
assets: false,
|
116
|
-
helper: false,
|
117
|
-
template_engine: nil
|
118
|
-
)
|
119
|
-
|
120
|
-
if ARGV.first == 'mailer'
|
121
|
-
options[:rails].merge!(template_engine: :erb)
|
71
|
+
class << self
|
72
|
+
def configure!(config) #:nodoc:
|
73
|
+
api_only! if config.api_only
|
74
|
+
no_color! unless config.colorize_logging
|
75
|
+
aliases.deep_merge! config.aliases
|
76
|
+
options.deep_merge! config.options
|
77
|
+
fallbacks.merge! config.fallbacks
|
78
|
+
templates_path.concat config.templates
|
79
|
+
templates_path.uniq!
|
80
|
+
hide_namespaces(*config.hidden_namespaces)
|
122
81
|
end
|
123
|
-
end
|
124
|
-
|
125
|
-
# Remove the color from output.
|
126
|
-
def self.no_color!
|
127
|
-
Thor::Base.shell = Thor::Shell::Basic
|
128
|
-
end
|
129
|
-
|
130
|
-
# Track all generators subclasses.
|
131
|
-
def self.subclasses
|
132
|
-
@subclasses ||= []
|
133
|
-
end
|
134
82
|
|
135
|
-
|
136
|
-
|
137
|
-
# Generators names must end with "_generator.rb". This is required because Rails
|
138
|
-
# looks in load paths and loads the generator just before it's going to be used.
|
139
|
-
#
|
140
|
-
# find_by_namespace :webrat, :rails, :integration
|
141
|
-
#
|
142
|
-
# Will search for the following generators:
|
143
|
-
#
|
144
|
-
# "rails:webrat", "webrat:integration", "webrat"
|
145
|
-
#
|
146
|
-
# Notice that "rails:generators:webrat" could be loaded as well, what
|
147
|
-
# Rails looks for is the first and last parts of the namespace.
|
148
|
-
def self.find_by_namespace(name, base=nil, context=nil) #:nodoc:
|
149
|
-
lookups = []
|
150
|
-
lookups << "#{base}:#{name}" if base
|
151
|
-
lookups << "#{name}:#{context}" if context
|
152
|
-
|
153
|
-
unless base || context
|
154
|
-
unless name.to_s.include?(?:)
|
155
|
-
lookups << "#{name}:#{name}"
|
156
|
-
lookups << "rails:#{name}"
|
157
|
-
end
|
158
|
-
lookups << "#{name}"
|
83
|
+
def templates_path #:nodoc:
|
84
|
+
@templates_path ||= []
|
159
85
|
end
|
160
86
|
|
161
|
-
|
87
|
+
def aliases #:nodoc:
|
88
|
+
@aliases ||= DEFAULT_ALIASES.dup
|
89
|
+
end
|
162
90
|
|
163
|
-
|
91
|
+
def options #:nodoc:
|
92
|
+
@options ||= DEFAULT_OPTIONS.dup
|
93
|
+
end
|
164
94
|
|
165
|
-
|
166
|
-
|
167
|
-
|
95
|
+
# Hold configured generators fallbacks. If a plugin developer wants a
|
96
|
+
# generator group to fallback to another group in case of missing generators,
|
97
|
+
# they can add a fallback.
|
98
|
+
#
|
99
|
+
# For example, shoulda is considered a test_framework and is an extension
|
100
|
+
# of test_unit. However, most part of shoulda generators are similar to
|
101
|
+
# test_unit ones.
|
102
|
+
#
|
103
|
+
# Shoulda then can tell generators to search for test_unit generators when
|
104
|
+
# some of them are not available by adding a fallback:
|
105
|
+
#
|
106
|
+
# Rails::Generators.fallbacks[:shoulda] = :test_unit
|
107
|
+
def fallbacks
|
108
|
+
@fallbacks ||= {}
|
168
109
|
end
|
169
110
|
|
170
|
-
|
171
|
-
|
111
|
+
# Configure generators for API only applications. It basically hides
|
112
|
+
# everything that is usually browser related, such as assets and session
|
113
|
+
# migration generators, and completely disable helpers and assets
|
114
|
+
# so generators such as scaffold won't create them.
|
115
|
+
def api_only!
|
116
|
+
hide_namespaces "assets", "helper", "css", "js"
|
117
|
+
|
118
|
+
options[:rails].merge!(
|
119
|
+
api: true,
|
120
|
+
assets: false,
|
121
|
+
helper: false,
|
122
|
+
template_engine: nil
|
123
|
+
)
|
124
|
+
|
125
|
+
if ARGV.first == "mailer"
|
126
|
+
options[:rails].merge!(template_engine: :erb)
|
127
|
+
end
|
128
|
+
end
|
172
129
|
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
def self.invoke(namespace, args=ARGV, config={})
|
177
|
-
names = namespace.to_s.split(':')
|
178
|
-
if klass = find_by_namespace(names.pop, names.any? && names.join(':'))
|
179
|
-
args << "--help" if args.empty? && klass.arguments.any?(&:required?)
|
180
|
-
klass.start(args, config)
|
181
|
-
else
|
182
|
-
options = sorted_groups.flat_map(&:last)
|
183
|
-
suggestions = options.sort_by {|suggested| levenshtein_distance(namespace.to_s, suggested) }.first(3)
|
184
|
-
msg = "Could not find generator '#{namespace}'. "
|
185
|
-
msg << "Maybe you meant #{ suggestions.map {|s| "'#{s}'"}.to_sentence(last_word_connector: " or ", locale: :en) }\n"
|
186
|
-
msg << "Run `rails generate --help` for more options."
|
187
|
-
puts msg
|
130
|
+
# Remove the color from output.
|
131
|
+
def no_color!
|
132
|
+
Thor::Base.shell = Thor::Shell::Basic
|
188
133
|
end
|
189
|
-
end
|
190
134
|
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
135
|
+
# Returns an array of generator namespaces that are hidden.
|
136
|
+
# Generator namespaces may be hidden for a variety of reasons.
|
137
|
+
# Some are aliased such as "rails:migration" and can be
|
138
|
+
# invoked with the shorter "migration", others are private to other generators
|
139
|
+
# such as "css:scaffold".
|
140
|
+
def hidden_namespaces
|
141
|
+
@hidden_namespaces ||= begin
|
142
|
+
orm = options[:rails][:orm]
|
143
|
+
test = options[:rails][:test_framework]
|
144
|
+
template = options[:rails][:template_engine]
|
145
|
+
css = options[:rails][:stylesheet_engine]
|
146
|
+
|
147
|
+
[
|
148
|
+
"rails",
|
149
|
+
"resource_route",
|
150
|
+
"#{orm}:migration",
|
151
|
+
"#{orm}:model",
|
152
|
+
"#{test}:controller",
|
153
|
+
"#{test}:helper",
|
154
|
+
"#{test}:integration",
|
155
|
+
"#{test}:system",
|
156
|
+
"#{test}:mailer",
|
157
|
+
"#{test}:model",
|
158
|
+
"#{test}:scaffold",
|
159
|
+
"#{test}:view",
|
160
|
+
"#{test}:job",
|
161
|
+
"#{template}:controller",
|
162
|
+
"#{template}:scaffold",
|
163
|
+
"#{template}:mailer",
|
164
|
+
"#{css}:scaffold",
|
165
|
+
"#{css}:assets",
|
166
|
+
"css:assets",
|
167
|
+
"css:scaffold"
|
168
|
+
]
|
169
|
+
end
|
224
170
|
end
|
225
|
-
end
|
226
171
|
|
227
|
-
class << self
|
228
172
|
def hide_namespaces(*namespaces)
|
229
173
|
hidden_namespaces.concat(namespaces)
|
230
174
|
end
|
231
175
|
alias hide_namespace hide_namespaces
|
232
|
-
end
|
233
176
|
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
print_generators
|
249
|
-
end
|
177
|
+
# Show help message with available generators.
|
178
|
+
def help(command = "generate")
|
179
|
+
puts "Usage: rails #{command} GENERATOR [args] [options]"
|
180
|
+
puts
|
181
|
+
puts "General options:"
|
182
|
+
puts " -h, [--help] # Print generator's options and usage"
|
183
|
+
puts " -p, [--pretend] # Run but do not make any changes"
|
184
|
+
puts " -f, [--force] # Overwrite files that already exist"
|
185
|
+
puts " -s, [--skip] # Skip files that already exist"
|
186
|
+
puts " -q, [--quiet] # Suppress status output"
|
187
|
+
puts
|
188
|
+
puts "Please choose a generator below."
|
189
|
+
puts
|
250
190
|
|
251
|
-
|
252
|
-
|
253
|
-
subclasses.map(&:namespace)
|
254
|
-
end
|
191
|
+
print_generators
|
192
|
+
end
|
255
193
|
|
256
|
-
|
257
|
-
|
258
|
-
|
194
|
+
def public_namespaces
|
195
|
+
lookup!
|
196
|
+
subclasses.map(&:namespace)
|
197
|
+
end
|
259
198
|
|
260
|
-
|
261
|
-
|
262
|
-
namespaces.sort!
|
263
|
-
groups = Hash.new { |h,k| h[k] = [] }
|
264
|
-
namespaces.each do |namespace|
|
265
|
-
base = namespace.split(':').first
|
266
|
-
groups[base] << namespace
|
199
|
+
def print_generators
|
200
|
+
sorted_groups.each { |b, n| print_list(b, n) }
|
267
201
|
end
|
268
|
-
rails = groups.delete("rails")
|
269
|
-
rails.map! { |n| n.sub(/^rails:/, '') }
|
270
|
-
rails.delete("app")
|
271
|
-
rails.delete("plugin")
|
272
202
|
|
273
|
-
|
203
|
+
def sorted_groups
|
204
|
+
namespaces = public_namespaces
|
205
|
+
namespaces.sort!
|
274
206
|
|
275
|
-
|
276
|
-
|
207
|
+
groups = Hash.new { |h, k| h[k] = [] }
|
208
|
+
namespaces.each do |namespace|
|
209
|
+
base = namespace.split(":").first
|
210
|
+
groups[base] << namespace
|
211
|
+
end
|
212
|
+
|
213
|
+
rails = groups.delete("rails")
|
214
|
+
rails.map! { |n| n.sub(/^rails:/, "") }
|
215
|
+
rails.delete("app")
|
216
|
+
rails.delete("plugin")
|
217
|
+
rails.delete("encrypted_secrets")
|
277
218
|
|
278
|
-
|
219
|
+
hidden_namespaces.each { |n| groups.delete(n.to_s) }
|
279
220
|
|
280
|
-
|
281
|
-
|
221
|
+
[[ "rails", rails ]] + groups.sort.to_a
|
222
|
+
end
|
223
|
+
|
224
|
+
# Rails finds namespaces similar to Thor, it only adds one rule:
|
225
|
+
#
|
226
|
+
# Generators names must end with "_generator.rb". This is required because Rails
|
227
|
+
# looks in load paths and loads the generator just before it's going to be used.
|
228
|
+
#
|
229
|
+
# find_by_namespace :webrat, :rails, :integration
|
282
230
|
#
|
283
|
-
#
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
str1.each_codepoint.with_index do |char1, i|
|
300
|
-
e = i+1
|
301
|
-
|
302
|
-
str2_codepoint_enumerable.with_index do |char2, j|
|
303
|
-
cost = (char1 == char2) ? 0 : 1
|
304
|
-
x = [
|
305
|
-
d[j+1] + 1, # insertion
|
306
|
-
e + 1, # deletion
|
307
|
-
d[j] + cost # substitution
|
308
|
-
].min
|
309
|
-
d[j] = e
|
310
|
-
e = x
|
231
|
+
# Will search for the following generators:
|
232
|
+
#
|
233
|
+
# "rails:webrat", "webrat:integration", "webrat"
|
234
|
+
#
|
235
|
+
# Notice that "rails:generators:webrat" could be loaded as well, what
|
236
|
+
# Rails looks for is the first and last parts of the namespace.
|
237
|
+
def find_by_namespace(name, base = nil, context = nil) #:nodoc:
|
238
|
+
lookups = []
|
239
|
+
lookups << "#{base}:#{name}" if base
|
240
|
+
lookups << "#{name}:#{context}" if context
|
241
|
+
|
242
|
+
unless base || context
|
243
|
+
unless name.to_s.include?(?:)
|
244
|
+
lookups << "#{name}:#{name}"
|
245
|
+
lookups << "rails:#{name}"
|
311
246
|
end
|
247
|
+
lookups << "#{name}"
|
248
|
+
end
|
249
|
+
|
250
|
+
lookup(lookups)
|
312
251
|
|
313
|
-
|
252
|
+
namespaces = Hash[subclasses.map { |klass| [klass.namespace, klass] }]
|
253
|
+
lookups.each do |namespace|
|
254
|
+
|
255
|
+
klass = namespaces[namespace]
|
256
|
+
return klass if klass
|
314
257
|
end
|
315
258
|
|
316
|
-
|
259
|
+
invoke_fallbacks_for(name, base) || invoke_fallbacks_for(context, name)
|
317
260
|
end
|
318
261
|
|
319
|
-
#
|
320
|
-
|
321
|
-
|
322
|
-
|
262
|
+
# Receives a namespace, arguments and the behavior to invoke the generator.
|
263
|
+
# It's used as the default entry point for generate, destroy and update
|
264
|
+
# commands.
|
265
|
+
def invoke(namespace, args = ARGV, config = {})
|
266
|
+
names = namespace.to_s.split(":")
|
267
|
+
if klass = find_by_namespace(names.pop, names.any? && names.join(":"))
|
268
|
+
args << "--help" if args.empty? && klass.arguments.any?(&:required?)
|
269
|
+
klass.start(args, config)
|
270
|
+
else
|
271
|
+
options = sorted_groups.flat_map(&:last)
|
272
|
+
suggestions = options.sort_by { |suggested| levenshtein_distance(namespace.to_s, suggested) }.first(3)
|
273
|
+
msg = "Could not find generator '#{namespace}'. "
|
274
|
+
msg << "Maybe you meant #{ suggestions.map { |s| "'#{s}'" }.to_sentence(last_word_connector: " or ", locale: :en) }\n"
|
275
|
+
msg << "Run `rails generate --help` for more options."
|
276
|
+
puts msg
|
323
277
|
end
|
278
|
+
end
|
324
279
|
|
325
|
-
|
326
|
-
puts "#{base.camelize}:"
|
280
|
+
private
|
327
281
|
|
328
|
-
namespaces
|
329
|
-
|
282
|
+
def print_list(base, namespaces) # :doc:
|
283
|
+
namespaces = namespaces.reject { |n| hidden_namespaces.include?(n) }
|
284
|
+
super
|
330
285
|
end
|
331
286
|
|
332
|
-
|
333
|
-
|
287
|
+
# Try fallbacks for the given base.
|
288
|
+
def invoke_fallbacks_for(name, base)
|
289
|
+
return nil unless base && fallbacks[base.to_sym]
|
290
|
+
invoked_fallbacks = []
|
334
291
|
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
invoked_fallbacks = []
|
292
|
+
Array(fallbacks[base.to_sym]).each do |fallback|
|
293
|
+
next if invoked_fallbacks.include?(fallback)
|
294
|
+
invoked_fallbacks << fallback
|
339
295
|
|
340
|
-
|
341
|
-
|
342
|
-
|
296
|
+
klass = find_by_namespace(name, fallback)
|
297
|
+
return klass if klass
|
298
|
+
end
|
343
299
|
|
344
|
-
|
345
|
-
return klass if klass
|
300
|
+
nil
|
346
301
|
end
|
347
302
|
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
# Receives namespaces in an array and tries to find matching generators
|
352
|
-
# in the load path.
|
353
|
-
def self.lookup(namespaces) #:nodoc:
|
354
|
-
paths = namespaces_to_paths(namespaces)
|
355
|
-
|
356
|
-
paths.each do |raw_path|
|
357
|
-
["rails/generators", "generators"].each do |base|
|
358
|
-
path = "#{base}/#{raw_path}_generator"
|
359
|
-
|
360
|
-
begin
|
361
|
-
require path
|
362
|
-
return
|
363
|
-
rescue LoadError => e
|
364
|
-
raise unless e.message =~ /#{Regexp.escape(path)}$/
|
365
|
-
rescue Exception => e
|
366
|
-
warn "[WARNING] Could not load generator #{path.inspect}. Error: #{e.message}.\n#{e.backtrace.join("\n")}"
|
367
|
-
end
|
368
|
-
end
|
303
|
+
def command_type # :doc:
|
304
|
+
@command_type ||= "generator"
|
369
305
|
end
|
370
|
-
end
|
371
306
|
|
372
|
-
|
373
|
-
|
374
|
-
$LOAD_PATH.each do |base|
|
375
|
-
Dir[File.join(base, "{rails/generators,generators}", "**", "*_generator.rb")].each do |path|
|
376
|
-
begin
|
377
|
-
path = path.sub("#{base}/", "")
|
378
|
-
require path
|
379
|
-
rescue Exception
|
380
|
-
# No problem
|
381
|
-
end
|
382
|
-
end
|
307
|
+
def lookup_paths # :doc:
|
308
|
+
@lookup_paths ||= %w( rails/generators generators )
|
383
309
|
end
|
384
|
-
end
|
385
310
|
|
386
|
-
|
387
|
-
|
388
|
-
# in both: "rails/model/model_generator" and "rails/model_generator".
|
389
|
-
def self.namespaces_to_paths(namespaces) #:nodoc:
|
390
|
-
paths = []
|
391
|
-
namespaces.each do |namespace|
|
392
|
-
pieces = namespace.split(":")
|
393
|
-
paths << pieces.dup.push(pieces.last).join("/")
|
394
|
-
paths << pieces.join("/")
|
311
|
+
def file_lookup_paths # :doc:
|
312
|
+
@file_lookup_paths ||= [ "{#{lookup_paths.join(',')}}", "**", "*_generator.rb" ]
|
395
313
|
end
|
396
|
-
|
397
|
-
paths
|
398
|
-
end
|
314
|
+
end
|
399
315
|
end
|
400
316
|
end
|