From a288b74f1c75c6f100de7611a5093a421f1ad6d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 28 Oct 2009 18:32:53 -0200 Subject: Generators should use Rails.root instead of Dir.pwd [#3408 status:resolved] Signed-off-by: Yehuda Katz --- railties/lib/rails/generators/base.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'railties/lib/rails') diff --git a/railties/lib/rails/generators/base.rb b/railties/lib/rails/generators/base.rb index 7af99797ea..e6baf2fc79 100644 --- a/railties/lib/rails/generators/base.rb +++ b/railties/lib/rails/generators/base.rb @@ -12,6 +12,16 @@ module Rails add_runtime_options! + # Always move to rails source root. + # + def initialize(*args) #:nodoc: + if !invoked?(args) && defined?(Rails.root) && Rails.root + self.destination_root = Rails.root + FileUtils.cd(destination_root) + end + super + end + # Automatically sets the source root based on the class name. # def self.source_root @@ -247,6 +257,13 @@ module Rails end end + # Check if this generator was invoked from another one by inspecting + # parameters. + # + def invoked?(args) + args.last.is_a?(Hash) && args.last.key?(:invocations) + end + # Use Rails default banner. # def self.banner -- cgit v1.2.3