0

我目前正在尝试从脚本中创建一个 ruby​​ gem,虽然如果我将脚本放在同一个目录中,如果我在生成我的 gem 结构后将它们放在适当的 /bin 和 /lib 目录中,它会起作用,构建gem,然后尝试执行它我得到了未初始化的常量错误。在 /bin 文件“cjp”中的相关部分是:

Cjb.new(crontabDir, logDir, allowedFrequency, printOnly, testRun).
    find_violations autoFix

该类在 /lib 下的文件 cjp.rb 中定义

class Cjb
  def initialize(crontabDir, logDir, allowedFrequency, printOnly, testRun)
    @crontabDir, @logDir, @allowedFrequency, @printOnly, @testRun =
      crontabDir, logDir, allowedFrequency, printOnly, testRun

尽管如此,我得到的错误是:

ERROR:  uninitialized constant Cjb

我还注意到,如果我尝试在 /bin 下手动执行“cjp”脚本而 lib 脚本不在同一目录中,它也会给出相同的错误。看来我错过了一些东西。

对于我在这里缺少的任何帮助,我们将不胜感激。

4

1 回答 1

0

bundle gem uses git to manage gem manifest.

If you do not see all your expected files when you run git ls-files in your gem project dir, then you need to add them.

To add individual files:

git add <filename>

To add everything (run from root of project):

git add .

This may have caught you out if you were not expecting to use git on your project. If you don't know git, and have time, it is really recommended to help you manage your project code. In fact so much so that bundle simply assumes that's what you want to do (although other code management tools are available)

于 2013-06-24T18:11:57.283 回答