aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/command
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/lib/rails/command
parent6813edc7d926965e5644cd8befaf229a35b9d8ca (diff)
downloadrails-d5bd4b259fa07aba81effaebfe2874ddfdf91bf5.tar.gz
rails-d5bd4b259fa07aba81effaebfe2874ddfdf91bf5.tar.bz2
rails-d5bd4b259fa07aba81effaebfe2874ddfdf91bf5.zip
Run engine commands through command infrastructure.
Diffstat (limited to 'railties/lib/rails/command')
-rw-r--r--railties/lib/rails/command/actions.rb36
-rw-r--r--railties/lib/rails/command/base.rb5
2 files changed, 35 insertions, 6 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)