我有一个简单的 rails install generator 用于我正在制作的引擎:
module Bouncer
module Generators
class InstallGenerator < Rails::Generators::Base
source_root File.expand_path("../../templates", __FILE__)
desc "Copies locale file and migrations to your application."
def copy_locale
copy_file "../../../config/locales/en.yml", "config/locales/bouncer.en.yml"
end
def copy_migrations
# I would like to run "rake bouncer_engine:install:migrations" right here
# rather than copy_file "../../../db/migrate/blah.rb", "db/migrate/blah.rb"
end
end
end
end
当用户运行rails g bouncer:install
时,一个语言环境文件被复制到他们的应用程序中。我也想复制我的迁移,但不是使用copy_file
方法,我希望我可以rake bouncer_engine:install:migrations
在生成器中运行,就像我从命令行做的那样。我怎样才能做到这一点?