我知道如何创建一个名为:
的rails生成器gemrails g my_generator command
我知道如何创建一个可以被称为:
的thor宝石my_generator command
但我不知道如何创建可以使用可执行文件调用的rails生成器。我试过创建一个lib / my_generator / cli.rb文件,如:
require 'thor'
module Mang
class Cli < Thor
include ::Rails::Generators::Base
desc "install_gem", "install a gem"
def install_gem
gem 'thor', "0.18.1"
end
end
end
但是,尽管在我的gemspec中添加了Rails作为依赖项,但我得到了以下错误。
uninitialized constant Rails (NameError)
答案 0 :(得分:0)
修复只是包含rails / generators / actions模块。
require 'thor'
require 'rails/generators'
require 'rails/generators/actions'
module Mang
class Cli < Thor
include Thor::Actions
include Rails::Generators::Actions
desc "install_gem", "install a gem"
def install_gem
gem 'thor', "0.18.1"
end
end
end