diff options
author | José Valim <jose.valim@gmail.com> | 2009-11-03 00:08:33 -0200 |
---|---|---|
committer | Engine Yard <engineyard@Engine-Yards-MacBook-Pro.local> | 2009-11-02 18:20:16 -0800 |
commit | d226f17507805c145cc7a1727d46714b88910094 (patch) | |
tree | 5fd52e0715c9d6c8f10b7a9ac9db1fa066a65eb0 /railties/lib | |
parent | 23780850237876cf81038534d8f59fa307af0b31 (diff) | |
download | rails-d226f17507805c145cc7a1727d46714b88910094.tar.gz rails-d226f17507805c145cc7a1727d46714b88910094.tar.bz2 rails-d226f17507805c145cc7a1727d46714b88910094.zip |
Ensure that generators can be invoked from any directory.
Signed-off-by: Engine Yard <engineyard@Engine-Yards-MacBook-Pro.local>
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/rails/generators/base.rb | 17 |
1 files changed, 17 insertions, 0 deletions
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 |