From d5bd4b259fa07aba81effaebfe2874ddfdf91bf5 Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Mon, 5 Sep 2016 22:14:55 +0200 Subject: Run engine commands through command infrastructure. --- railties/lib/rails/command/actions.rb | 36 +++++++++++++++++++++++++++++------ railties/lib/rails/command/base.rb | 5 +++++ 2 files changed, 35 insertions(+), 6 deletions(-) (limited to 'railties/lib/rails/command') 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) -- cgit v1.2.3