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.
Files changed (197) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +77 -567
  3. data/MIT-LICENSE +1 -1
  4. data/RDOC_MAIN.rdoc +3 -3
  5. data/README.rdoc +1 -1
  6. data/exe/rails +2 -2
  7. data/lib/rails.rb +18 -18
  8. data/lib/rails/all.rb +1 -1
  9. data/lib/rails/api/generator.rb +28 -0
  10. data/lib/rails/api/task.rb +54 -42
  11. data/lib/rails/app_loader.rb +9 -9
  12. data/lib/rails/application.rb +30 -35
  13. data/lib/rails/application/bootstrap.rb +13 -7
  14. data/lib/rails/application/configuration.rb +30 -53
  15. data/lib/rails/application/default_middleware_stack.rb +3 -5
  16. data/lib/rails/application/finisher.rb +16 -7
  17. data/lib/rails/application/routes_reloader.rb +16 -1
  18. data/lib/rails/application_controller.rb +10 -10
  19. data/lib/rails/backtrace_cleaner.rb +5 -5
  20. data/lib/rails/cli.rb +7 -5
  21. data/lib/rails/code_statistics.rb +16 -17
  22. data/lib/rails/code_statistics_calculator.rb +3 -3
  23. data/lib/rails/command.rb +111 -0
  24. data/lib/rails/command/actions.rb +42 -0
  25. data/lib/rails/command/base.rb +149 -0
  26. data/lib/rails/command/behavior.rb +123 -0
  27. data/lib/rails/command/environment_argument.rb +34 -0
  28. data/lib/rails/commands.rb +2 -4
  29. data/lib/rails/commands/application/application_command.rb +29 -0
  30. data/lib/rails/commands/console/console_command.rb +89 -0
  31. data/lib/rails/commands/dbconsole/dbconsole_command.rb +155 -0
  32. data/lib/rails/commands/destroy/destroy_command.rb +21 -0
  33. data/lib/rails/commands/generate/generate_command.rb +23 -0
  34. data/lib/rails/commands/help/USAGE +15 -0
  35. data/lib/rails/commands/help/help_command.rb +13 -0
  36. data/lib/rails/commands/new/new_command.rb +15 -0
  37. data/lib/rails/commands/plugin/plugin_command.rb +43 -0
  38. data/lib/rails/commands/rake/rake_command.rb +49 -0
  39. data/lib/rails/commands/runner/USAGE +17 -0
  40. data/lib/rails/commands/runner/runner_command.rb +46 -0
  41. data/lib/rails/commands/secrets/USAGE +52 -0
  42. data/lib/rails/commands/secrets/secrets_command.rb +36 -0
  43. data/lib/rails/commands/server/server_command.rb +177 -0
  44. data/lib/rails/commands/test/test_command.rb +20 -0
  45. data/lib/rails/commands/version/version_command.rb +9 -0
  46. data/lib/rails/configuration.rb +7 -7
  47. data/lib/rails/console/app.rb +4 -4
  48. data/lib/rails/dev_caching.rb +8 -8
  49. data/lib/rails/engine.rb +62 -63
  50. data/lib/rails/engine/commands.rb +6 -13
  51. data/lib/rails/engine/configuration.rb +2 -2
  52. data/lib/rails/gem_version.rb +3 -3
  53. data/lib/rails/generators.rb +229 -313
  54. data/lib/rails/generators/actions.rb +20 -21
  55. data/lib/rails/generators/actions/create_migration.rb +24 -25
  56. data/lib/rails/generators/active_model.rb +3 -3
  57. data/lib/rails/generators/app_base.rb +123 -93
  58. data/lib/rails/generators/base.rb +32 -33
  59. data/lib/rails/generators/css/assets/assets_generator.rb +1 -1
  60. data/lib/rails/generators/erb.rb +14 -14
  61. data/lib/rails/generators/erb/controller/controller_generator.rb +1 -1
  62. data/lib/rails/generators/erb/mailer/mailer_generator.rb +12 -12
  63. data/lib/rails/generators/erb/scaffold/scaffold_generator.rb +3 -3
  64. data/lib/rails/generators/generated_attribute.rb +27 -27
  65. data/lib/rails/generators/js/assets/assets_generator.rb +1 -1
  66. data/lib/rails/generators/migration.rb +8 -8
  67. data/lib/rails/generators/model_helpers.rb +2 -2
  68. data/lib/rails/generators/named_base.rb +56 -56
  69. data/lib/rails/generators/rails/app/app_generator.rb +98 -81
  70. data/lib/rails/generators/rails/app/templates/Gemfile +7 -2
  71. data/lib/rails/generators/rails/app/templates/app/assets/config/manifest.js.tt +0 -2
  72. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +6 -4
  73. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/cable.js +1 -1
  74. data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +2 -2
  75. data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +1 -1
  76. data/lib/rails/generators/rails/app/templates/bin/{setup → setup.tt} +6 -0
  77. data/lib/rails/generators/rails/app/templates/bin/{update → update.tt} +2 -1
  78. data/lib/rails/generators/rails/app/templates/bin/yarn +9 -0
  79. data/lib/rails/generators/rails/app/templates/config/cable.yml +1 -0
  80. data/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml +1 -0
  81. data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml +1 -0
  82. data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml +1 -0
  83. data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml +2 -1
  84. data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml +1 -0
  85. data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml +1 -0
  86. data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml +2 -2
  87. data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml +1 -0
  88. data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml +1 -1
  89. data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml +1 -1
  90. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +1 -1
  91. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +10 -1
  92. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +1 -1
  93. data/lib/rails/generators/rails/app/templates/config/initializers/application_controller_renderer.rb +4 -6
  94. data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +8 -3
  95. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults.rb.tt +6 -5
  96. data/lib/rails/generators/rails/app/templates/config/locales/en.yml +10 -0
  97. data/lib/rails/generators/rails/app/templates/config/puma.rb +16 -7
  98. data/lib/rails/generators/rails/app/templates/config/secrets.yml +12 -2
  99. data/lib/rails/generators/rails/app/templates/gitignore +5 -1
  100. data/lib/rails/generators/rails/app/templates/package.json +5 -0
  101. data/lib/rails/generators/rails/app/templates/public/404.html +6 -6
  102. data/lib/rails/generators/rails/app/templates/public/422.html +6 -6
  103. data/lib/rails/generators/rails/app/templates/public/500.html +6 -6
  104. data/lib/rails/generators/rails/app/templates/public/robots.txt +0 -4
  105. data/lib/rails/generators/rails/app/templates/test/application_system_test_case.rb +5 -0
  106. data/lib/rails/generators/rails/app/templates/test/test_helper.rb +0 -1
  107. data/lib/rails/generators/rails/assets/assets_generator.rb +10 -10
  108. data/lib/rails/generators/rails/controller/controller_generator.rb +15 -12
  109. data/lib/rails/generators/rails/encrypted_secrets/encrypted_secrets_generator.rb +66 -0
  110. data/lib/rails/generators/rails/encrypted_secrets/templates/config/secrets.yml.enc +3 -0
  111. data/lib/rails/generators/rails/generator/generator_generator.rb +2 -3
  112. data/lib/rails/generators/rails/helper/helper_generator.rb +1 -1
  113. data/lib/rails/generators/rails/model/model_generator.rb +1 -1
  114. data/lib/rails/generators/rails/plugin/plugin_generator.rb +21 -26
  115. data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +1 -0
  116. data/lib/rails/generators/rails/plugin/templates/bin/test.tt +3 -9
  117. data/lib/rails/generators/rails/plugin/templates/test/application_system_test_case.rb +5 -0
  118. data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb +0 -3
  119. data/lib/rails/generators/rails/resource/resource_generator.rb +2 -2
  120. data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +5 -1
  121. data/lib/rails/generators/rails/scaffold/templates/scaffold.css +4 -8
  122. data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +2 -3
  123. data/lib/rails/generators/rails/system_test/USAGE +10 -0
  124. data/lib/rails/generators/rails/system_test/system_test_generator.rb +7 -0
  125. data/lib/rails/generators/rails/task/task_generator.rb +1 -2
  126. data/lib/rails/generators/resource_helpers.rb +13 -10
  127. data/lib/rails/generators/test_case.rb +5 -6
  128. data/lib/rails/generators/test_unit.rb +1 -1
  129. data/lib/rails/generators/test_unit/controller/controller_generator.rb +3 -3
  130. data/lib/rails/generators/test_unit/generator/generator_generator.rb +3 -3
  131. data/lib/rails/generators/test_unit/helper/helper_generator.rb +1 -1
  132. data/lib/rails/generators/test_unit/integration/integration_generator.rb +2 -2
  133. data/lib/rails/generators/test_unit/job/job_generator.rb +3 -3
  134. data/lib/rails/generators/test_unit/mailer/mailer_generator.rb +5 -5
  135. data/lib/rails/generators/test_unit/model/model_generator.rb +3 -4
  136. data/lib/rails/generators/test_unit/plugin/plugin_generator.rb +2 -2
  137. data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +3 -3
  138. data/lib/rails/generators/test_unit/system/system_generator.rb +17 -0
  139. data/lib/rails/generators/test_unit/system/templates/application_system_test_case.rb +5 -0
  140. data/lib/rails/generators/test_unit/system/templates/system_test.rb +9 -0
  141. data/lib/rails/generators/testing/assertions.rb +4 -4
  142. data/lib/rails/generators/testing/behaviour.rb +20 -21
  143. data/lib/rails/info.rb +20 -20
  144. data/lib/rails/info_controller.rb +15 -15
  145. data/lib/rails/initializable.rb +6 -2
  146. data/lib/rails/mailers_controller.rb +11 -11
  147. data/lib/rails/paths.rb +4 -5
  148. data/lib/rails/plugin/test.rb +7 -0
  149. data/lib/rails/rack/logger.rb +44 -46
  150. data/lib/rails/railtie.rb +41 -38
  151. data/lib/rails/railtie/configurable.rb +6 -6
  152. data/lib/rails/railtie/configuration.rb +1 -1
  153. data/lib/rails/ruby_version_check.rb +1 -1
  154. data/lib/rails/secrets.rb +111 -0
  155. data/lib/rails/source_annotation_extractor.rb +15 -9
  156. data/lib/rails/tasks.rb +3 -2
  157. data/lib/rails/tasks/annotations.rake +3 -3
  158. data/lib/rails/tasks/dev.rake +2 -2
  159. data/lib/rails/tasks/engine.rake +4 -4
  160. data/lib/rails/tasks/framework.rake +4 -18
  161. data/lib/rails/tasks/initializers.rake +1 -1
  162. data/lib/rails/tasks/log.rake +14 -10
  163. data/lib/rails/tasks/middleware.rake +1 -1
  164. data/lib/rails/tasks/misc.rake +10 -10
  165. data/lib/rails/tasks/restart.rake +4 -4
  166. data/lib/rails/tasks/routes.rake +3 -12
  167. data/lib/rails/tasks/statistics.rake +3 -3
  168. data/lib/rails/tasks/tmp.rake +7 -7
  169. data/lib/rails/tasks/yarn.rake +11 -0
  170. data/lib/rails/templates/rails/mailers/email.html.erb +4 -1
  171. data/lib/rails/test_help.rb +28 -10
  172. data/lib/rails/test_unit/line_filtering.rb +69 -3
  173. data/lib/rails/test_unit/minitest_plugin.rb +139 -0
  174. data/lib/rails/test_unit/railtie.rb +2 -1
  175. data/lib/rails/test_unit/reporter.rb +3 -8
  176. data/lib/rails/test_unit/test_requirer.rb +28 -0
  177. data/lib/rails/test_unit/testing.rake +19 -14
  178. data/lib/rails/version.rb +1 -1
  179. data/lib/rails/welcome_controller.rb +1 -1
  180. metadata +53 -30
  181. data/lib/minitest/rails_plugin.rb +0 -49
  182. data/lib/rails/commands/application.rb +0 -17
  183. data/lib/rails/commands/commands_tasks.rb +0 -180
  184. data/lib/rails/commands/console.rb +0 -68
  185. data/lib/rails/commands/console_helper.rb +0 -34
  186. data/lib/rails/commands/dbconsole.rb +0 -173
  187. data/lib/rails/commands/destroy.rb +0 -11
  188. data/lib/rails/commands/generate.rb +0 -13
  189. data/lib/rails/commands/plugin.rb +0 -23
  190. data/lib/rails/commands/rake_proxy.rb +0 -41
  191. data/lib/rails/commands/runner.rb +0 -71
  192. data/lib/rails/commands/server.rb +0 -163
  193. data/lib/rails/commands/test.rb +0 -10
  194. data/lib/rails/engine/commands_tasks.rb +0 -118
  195. data/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +0 -3
  196. data/lib/rails/rack/debugger.rb +0 -3
  197. data/lib/rails/test_unit/runner.rb +0 -141
@@ -1,11 +1,11 @@
1
- require 'active_support/all'
2
- require 'action_controller'
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
@@ -1,27 +1,27 @@
1
- require 'fileutils'
1
+ require "fileutils"
2
2
 
3
3
  module Rails
4
4
  module DevCaching # :nodoc:
5
5
  class << self
6
- FILE = 'tmp/caching-dev.txt'
6
+ FILE = "tmp/caching-dev.txt"
7
7
 
8
8
  def enable_by_file
9
- FileUtils.mkdir_p('tmp')
9
+ FileUtils.mkdir_p("tmp")
10
10
 
11
11
  if File.exist?(FILE)
12
12
  delete_cache_file
13
- puts 'Development mode is no longer being cached.'
13
+ puts "Development mode is no longer being cached."
14
14
  else
15
15
  create_cache_file
16
- puts 'Development mode is now being cached.'
16
+ puts "Development mode is now being cached."
17
17
  end
18
18
 
19
- FileUtils.touch 'tmp/restart.txt'
20
- FileUtils.rm_f('tmp/pids/server.pid')
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('tmp')
24
+ FileUtils.mkdir_p("tmp")
25
25
 
26
26
  if caching
27
27
  create_cache_file
@@ -1,8 +1,8 @@
1
- require 'rails/railtie'
2
- require 'rails/engine/railties'
3
- require 'active_support/core_ext/module/delegation'
4
- require 'pathname'
5
- require 'thread'
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 rack application. It can be useful if you have a rack application that
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 rack endpoint, it can also have a middleware
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
- self.routes.default_scope = { module: ActiveSupport::Inflector.underscore(mod.name) }
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 rack application for this engine.
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 ruby load paths and remove duplicates.
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 = self.paths["config/routes.rb"].existent
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 self.is_a?(Rails::Application)
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
- def load_config_initializer(initializer)
647
- ActiveSupport::Notifications.instrument('load_config_initializer.railties', initializer: initializer) do
648
- load(initializer)
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
- def run_tasks_blocks(*) #:nodoc:
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
- def self.find_root_with_flag(flag, root_path, default=nil) #:nodoc:
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
- while root_path && File.directory?(root_path) && !File.exist?("#{root_path}/#{flag}")
664
- parent = File.dirname(root_path)
665
- root_path = parent != root_path && parent
659
+ def has_migrations?
660
+ paths["db/migrate"].existent.any?
666
661
  end
667
662
 
668
- root = File.exist?("#{root_path}/#{flag}") ? root_path : default
669
- raise "Could not find root path for #{self}" unless root
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
- Pathname.new File.realpath root
672
- end
669
+ root = File.exist?("#{root_path}/#{flag}") ? root_path : default
670
+ raise "Could not find root path for #{self}" unless root
673
671
 
674
- def default_middleware_stack #:nodoc:
675
- ActionDispatch::MiddlewareStack.new
676
- end
672
+ Pathname.new File.realpath root
673
+ end
677
674
 
678
- def _all_autoload_once_paths #:nodoc:
679
- config.autoload_once_paths
680
- end
675
+ def default_middleware_stack
676
+ ActionDispatch::MiddlewareStack.new
677
+ end
681
678
 
682
- def _all_autoload_paths #:nodoc:
683
- @_all_autoload_paths ||= (config.autoload_paths + config.eager_load_paths + config.autoload_once_paths).uniq
684
- end
679
+ def _all_autoload_once_paths
680
+ config.autoload_once_paths
681
+ end
685
682
 
686
- def _all_load_paths #:nodoc:
687
- @_all_load_paths ||= (config.paths.load_paths + _all_autoload_paths).uniq
688
- end
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
- private
687
+ def _all_load_paths
688
+ @_all_load_paths ||= (config.paths.load_paths + _all_autoload_paths).uniq
689
+ end
691
690
 
692
- def build_request(env)
693
- env.merge!(env_config)
694
- req = ActionDispatch::Request.new env
695
- req.routes = routes
696
- req.engine_script_name = req.script_name
697
- req
698
- end
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
- def build_middleware
701
- config.middleware
702
- end
699
+ def build_middleware
700
+ config.middleware
701
+ end
703
702
  end
704
703
  end
@@ -1,14 +1,7 @@
1
- require 'rails/engine/commands_tasks'
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
- ARGV << '--help' if ARGV.empty?
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 'rails/railtie/configuration'
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
@@ -6,9 +6,9 @@ module Rails
6
6
 
7
7
  module VERSION
8
8
  MAJOR = 5
9
- MINOR = 0
10
- TINY = 7
11
- PRE = "2"
9
+ MINOR = 1
10
+ TINY = 0
11
+ PRE = "beta1"
12
12
 
13
13
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
14
14
  end
@@ -1,45 +1,48 @@
1
- activesupport_path = File.expand_path('../../../../activesupport/lib', __FILE__)
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 'thor/group'
4
+ require "thor/group"
5
+ require "rails/command"
5
6
 
6
- require 'active_support'
7
- require 'active_support/core_ext/object/blank'
8
- require 'active_support/core_ext/kernel/singleton_class'
9
- require 'active_support/core_ext/array/extract_options'
10
- require 'active_support/core_ext/hash/deep_merge'
11
- require 'active_support/core_ext/module/attribute_accessors'
12
- require 'active_support/core_ext/string/inflections'
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
- autoload :Actions, 'rails/generators/actions'
17
- autoload :ActiveModel, 'rails/generators/active_model'
18
- autoload :Base, 'rails/generators/base'
19
- autoload :Migration, 'rails/generators/migration'
20
- autoload :NamedBase, 'rails/generators/named_base'
21
- autoload :ResourceHelpers, 'rails/generators/resource_helpers'
22
- autoload :TestCase, 'rails/generators/test_case'
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: '-a',
29
- orm: '-o',
30
- javascripts: '-j',
31
- javascript_engine: '-je',
32
- resource_controller: '-c',
33
- scaffold_controller: '-c',
34
- stylesheets: '-y',
35
- stylesheet_engine: '-se',
36
- scaffold_stylesheet: '-ss',
37
- template_engine: '-e',
38
- test_framework: '-t'
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: '-r',
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
- test_framework: nil,
65
+ system_tests: nil,
66
+ test_framework: false,
63
67
  template_engine: :erb
64
68
  }
65
69
  }
66
70
 
67
- def self.configure!(config) #:nodoc:
68
- api_only! if config.api_only
69
- no_color! unless config.colorize_logging
70
- aliases.deep_merge! config.aliases
71
- options.deep_merge! config.options
72
- fallbacks.merge! config.fallbacks
73
- templates_path.concat config.templates
74
- templates_path.uniq!
75
- hide_namespaces(*config.hidden_namespaces)
76
- end
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
- # Rails finds namespaces similar to thor, it only adds one rule:
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
- lookup(lookups)
87
+ def aliases #:nodoc:
88
+ @aliases ||= DEFAULT_ALIASES.dup
89
+ end
162
90
 
163
- namespaces = Hash[subclasses.map { |klass| [klass.namespace, klass] }]
91
+ def options #:nodoc:
92
+ @options ||= DEFAULT_OPTIONS.dup
93
+ end
164
94
 
165
- lookups.each do |namespace|
166
- klass = namespaces[namespace]
167
- return klass if klass
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
- invoke_fallbacks_for(name, base) || invoke_fallbacks_for(context, name)
171
- end
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
- # Receives a namespace, arguments and the behavior to invoke the generator.
174
- # It's used as the default entry point for generate, destroy and update
175
- # commands.
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
- # Returns an array of generator namespaces that are hidden.
192
- # Generator namespaces may be hidden for a variety of reasons.
193
- # Some are aliased such as "rails:migration" and can be
194
- # invoked with the shorter "migration", others are private to other generators
195
- # such as "css:scaffold".
196
- def self.hidden_namespaces
197
- @hidden_namespaces ||= begin
198
- orm = options[:rails][:orm]
199
- test = options[:rails][:test_framework]
200
- template = options[:rails][:template_engine]
201
- css = options[:rails][:stylesheet_engine]
202
-
203
- [
204
- "rails",
205
- "resource_route",
206
- "#{orm}:migration",
207
- "#{orm}:model",
208
- "#{test}:controller",
209
- "#{test}:helper",
210
- "#{test}:integration",
211
- "#{test}:mailer",
212
- "#{test}:model",
213
- "#{test}:scaffold",
214
- "#{test}:view",
215
- "#{test}:job",
216
- "#{template}:controller",
217
- "#{template}:scaffold",
218
- "#{template}:mailer",
219
- "#{css}:scaffold",
220
- "#{css}:assets",
221
- "css:assets",
222
- "css:scaffold"
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
- # Show help message with available generators.
235
- def self.help(command = 'generate')
236
- puts "Usage: rails #{command} GENERATOR [args] [options]"
237
- puts
238
- puts "General options:"
239
- puts " -h, [--help] # Print generator's options and usage"
240
- puts " -p, [--pretend] # Run but do not make any changes"
241
- puts " -f, [--force] # Overwrite files that already exist"
242
- puts " -s, [--skip] # Skip files that already exist"
243
- puts " -q, [--quiet] # Suppress status output"
244
- puts
245
- puts "Please choose a generator below."
246
- puts
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
- def self.public_namespaces
252
- lookup!
253
- subclasses.map(&:namespace)
254
- end
191
+ print_generators
192
+ end
255
193
 
256
- def self.print_generators
257
- sorted_groups.each { |b, n| print_list(b, n) }
258
- end
194
+ def public_namespaces
195
+ lookup!
196
+ subclasses.map(&:namespace)
197
+ end
259
198
 
260
- def self.sorted_groups
261
- namespaces = public_namespaces
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
- hidden_namespaces.each { |n| groups.delete(n.to_s) }
203
+ def sorted_groups
204
+ namespaces = public_namespaces
205
+ namespaces.sort!
274
206
 
275
- [["rails", rails]] + groups.sort.to_a
276
- end
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
- protected
219
+ hidden_namespaces.each { |n| groups.delete(n.to_s) }
279
220
 
280
- # This code is based directly on the Text gem implementation.
281
- # Copyright (c) 2006-2013 Paul Battley, Michael Neumann, Tim Fletcher.
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
- # Returns a value representing the "cost" of transforming str1 into str2
284
- def self.levenshtein_distance str1, str2
285
- s = str1
286
- t = str2
287
- n = s.length
288
- m = t.length
289
-
290
- return m if (0 == n)
291
- return n if (0 == m)
292
-
293
- d = (0..m).to_a
294
- x = nil
295
-
296
- # avoid duplicating an enumerable object in the loop
297
- str2_codepoint_enumerable = str2.each_codepoint
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
- d[m] = x
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
- x
259
+ invoke_fallbacks_for(name, base) || invoke_fallbacks_for(context, name)
317
260
  end
318
261
 
319
- # Prints a list of generators.
320
- def self.print_list(base, namespaces) #:nodoc:
321
- namespaces = namespaces.reject do |n|
322
- hidden_namespaces.include?(n)
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
- return if namespaces.empty?
326
- puts "#{base.camelize}:"
280
+ private
327
281
 
328
- namespaces.each do |namespace|
329
- puts(" #{namespace}")
282
+ def print_list(base, namespaces) # :doc:
283
+ namespaces = namespaces.reject { |n| hidden_namespaces.include?(n) }
284
+ super
330
285
  end
331
286
 
332
- puts
333
- end
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
- # Try fallbacks for the given base.
336
- def self.invoke_fallbacks_for(name, base) #:nodoc:
337
- return nil unless base && fallbacks[base.to_sym]
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
- Array(fallbacks[base.to_sym]).each do |fallback|
341
- next if invoked_fallbacks.include?(fallback)
342
- invoked_fallbacks << fallback
296
+ klass = find_by_namespace(name, fallback)
297
+ return klass if klass
298
+ end
343
299
 
344
- klass = find_by_namespace(name, fallback)
345
- return klass if klass
300
+ nil
346
301
  end
347
302
 
348
- nil
349
- end
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
- # This will try to load any generator in the load path to show in help.
373
- def self.lookup! #:nodoc:
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
- # Convert namespaces to paths by replacing ":" for "/" and adding
387
- # an extra lookup. For example, "rails:model" should be searched
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
- paths.uniq!
397
- paths
398
- end
314
+ end
399
315
  end
400
316
  end