aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorKasper Timm Hansen <kaspth@gmail.com>2016-09-05 22:14:55 +0200
committerKasper Timm Hansen <kaspth@gmail.com>2016-09-25 21:31:35 +0200
commitd5bd4b259fa07aba81effaebfe2874ddfdf91bf5 (patch)
treeb8814bb3ac0cbfd11ac11eacb7038f612620348f /railties
parent6813edc7d926965e5644cd8befaf229a35b9d8ca (diff)
downloadrails-d5bd4b259fa07aba81effaebfe2874ddfdf91bf5.tar.gz
rails-d5bd4b259fa07aba81effaebfe2874ddfdf91bf5.tar.bz2
rails-d5bd4b259fa07aba81effaebfe2874ddfdf91bf5.zip
Run engine commands through command infrastructure.
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/command/actions.rb36
-rw-r--r--railties/lib/rails/command/base.rb5
-rw-r--r--railties/lib/rails/commands/help/USAGE13
-rw-r--r--railties/lib/rails/commands/rake/rake_command.rb6
-rw-r--r--railties/lib/rails/engine/commands.rb6
-rw-r--r--railties/lib/rails/engine/commands_tasks.rb2
6 files changed, 54 insertions, 14 deletions
diff --git a/railties/lib/rails/command/actions.rb b/railties/lib/rails/command/actions.rb
index 52d3348db3..31b656ec31 100644
--- a/railties/lib/rails/command/actions.rb
+++ b/railties/lib/rails/command/actions.rb
@@ -1,18 +1,42 @@
module Rails
module Command
module Actions
- private
- # Change to the application's path if there is no config.ru file in current directory.
- # This allows us to run `rails server` from other directories, but still get
- # the main config.ru and properly set the tmp directory.
- def set_application_directory!
- Dir.chdir(File.expand_path("../../", APP_PATH)) unless File.exist?(File.expand_path("config.ru"))
+ # Change to the application's path if there is no config.ru file in current directory.
+ # This allows us to run `rails server` from other directories, but still get
+ # the main config.ru and properly set the tmp directory.
+ def set_application_directory!
+ Dir.chdir(File.expand_path("../../", APP_PATH)) unless File.exist?(File.expand_path("config.ru"))
+ end
+
+ if defined?(ENGINE_PATH)
+ def require_application_and_environment!
+ require ENGINE_PATH
end
+ def load_tasks
+ Rake.application.init("rails")
+ Rake.application.load_rakefile
+ end
+
+ def load_generators
+ engine = ::Rails::Engine.find(ENGINE_ROOT)
+ Rails::Generators.namespace = engine.railtie_namespace
+ engine.load_generators
+ end
+ else
def require_application_and_environment!
require APP_PATH
Rails.application.require_environment!
end
+
+ def load_tasks
+ Rails.application.load_tasks
+ end
+
+ def load_generators
+ Rails.application.load_generators
+ end
+ end
end
end
end
diff --git a/railties/lib/rails/command/base.rb b/railties/lib/rails/command/base.rb
index 2ef8393863..73ebaca66f 100644
--- a/railties/lib/rails/command/base.rb
+++ b/railties/lib/rails/command/base.rb
@@ -15,6 +15,11 @@ module Rails
include Actions
class << self
+ # Returns true when the app is a Rails engine.
+ def engine?
+ defined?(ENGINE_ROOT)
+ end
+
# Tries to get the description from a USAGE file one folder above the command
# root.
def desc(usage = nil, description = nil)
diff --git a/railties/lib/rails/commands/help/USAGE b/railties/lib/rails/commands/help/USAGE
index 0f6ff756ce..348f41861f 100644
--- a/railties/lib/rails/commands/help/USAGE
+++ b/railties/lib/rails/commands/help/USAGE
@@ -1,5 +1,16 @@
Usage: bin/rails COMMAND [args] [options]
+<% if engine? %>
+The common Rails commands available for engines are:
+ generate Generate new code (short-cut alias: "g")
+ destroy Undo code generated with "generate" (short-cut alias: "d")
+ test Run tests (short-cut alias: "t")
+All commands can be run with -h for more information.
+
+If you want to run any commands that need to be run in context
+of the application, like `bin/rails server` or `bin/rails console`,
+you should do it from the application's directory (typically test/dummy).
+<% else %>
The most common rails commands are:
generate Generate new code (short-cut alias: "g")
console Start the Rails console (short-cut alias: "c")
@@ -11,6 +22,6 @@ The most common rails commands are:
new application called MyApp in "./my_app"
All commands can be run with -h (or --help) for more information.
-
+<% end %>
In addition to those commands, there are:
diff --git a/railties/lib/rails/commands/rake/rake_command.rb b/railties/lib/rails/commands/rake/rake_command.rb
index a4a2464445..a43c884170 100644
--- a/railties/lib/rails/commands/rake/rake_command.rb
+++ b/railties/lib/rails/commands/rake/rake_command.rb
@@ -1,6 +1,8 @@
module Rails
module Command
class RakeCommand < Base
+ extend Rails::Command::Actions
+
namespace "rake"
class << self
@@ -27,12 +29,12 @@ module Rails
return @rake_tasks if defined?(@rake_tasks)
ActiveSupport::Deprecation.silence do
- Rails::Command.require_application_and_environment!
+ require_application_and_environment!
end
Rake::TaskManager.record_task_metadata = true
Rake.application.instance_variable_set(:@name, "rails")
- Rails.application.load_tasks
+ load_tasks
@rake_tasks = Rake.application.tasks.select(&:comment)
end
diff --git a/railties/lib/rails/engine/commands.rb b/railties/lib/rails/engine/commands.rb
index dfbeea36b8..a23ae44b0b 100644
--- a/railties/lib/rails/engine/commands.rb
+++ b/railties/lib/rails/engine/commands.rb
@@ -1,6 +1,4 @@
-require "rails/engine/commands_tasks"
-
-ARGV << "--help" if ARGV.empty?
+require "rails/command"
aliases = {
"g" => "generate",
@@ -11,4 +9,4 @@ aliases = {
command = ARGV.shift
command = aliases[command] || command
-Rails::Engine::CommandsTasks.new(ARGV).run_command!(command)
+Rails::Command.invoke command, ARGV
diff --git a/railties/lib/rails/engine/commands_tasks.rb b/railties/lib/rails/engine/commands_tasks.rb
index d6effdb732..65dd274793 100644
--- a/railties/lib/rails/engine/commands_tasks.rb
+++ b/railties/lib/rails/engine/commands_tasks.rb
@@ -26,7 +26,7 @@ module Rails
def help_message
<<-EOT.strip_heredoc
- Usage: rails COMMAND [ARGS]
+ Usage: bin/rails COMMAND [ARGS]
The common Rails commands available for engines are:
generate Generate new code (short-cut alias: "g")