如何在开发新gem时添加和打包新功能

时间:2018-02-07 21:25:25

标签: ruby rubygems rvm bundler

我刚刚创建了一个名为maker的示例gem。我也在使用RVM。

this PR中提供了添加示例用户功能的最新更改。我一直在Bundler文档中关注this guide来创建一个新的gem。

我目前正尝试通过irb使用gem,当我执行require maker时,我收到以下错误:

 :001 > require 'maker'
LoadError: cannot load such file -- maker/user
    from /Users/mohnishgj/.rvm/rubies/ruby-2.4.1/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /Users/mohnishgj/.rvm/rubies/ruby-2.4.1/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /Users/mohnishgj/.rvm/gems/ruby-2.4.1@experiments/gems/maker-0.1.0/lib/maker.rb:2:in `<top (required)>'
    from /Users/mohnishgj/.rvm/rubies/ruby-2.4.1/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:133:in `require'
    from /Users/mohnishgj/.rvm/rubies/ruby-2.4.1/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:133:in `rescue in require'
    from /Users/mohnishgj/.rvm/rubies/ruby-2.4.1/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:40:in `require'
    from (irb):1
    from /Users/mohnishgj/.rvm/rubies/ruby-2.4.1/bin/irb:11:in `<main>'
 :002 >

当我导航到experiments宝石集所安装宝石的地方时(即/Users/mohnishgj/.rvm/gems/ruby-2.4.1@experiments/gems/maker-0.1.0,我清楚地看到 该位置缺少user.rb个文件。

/Users/mohnishgj/.rvm/gems/ruby-2.4.1@experiments/gems/maker-0.1.0/lib/maker
➜  maker ls
version.rb

每当我想要将新文件添加为gem的一部分并希望它在irb之外工作时,我该如何解决这个问题。 我错误地做了宝石相关开发的一部分?请原谅我的无知,我创造宝石相对较新。 我应该如何正确地从源头开展与宝石相关的开发?

此外,我可能会遗漏一些内容,但是当我尝试将Bundler.require(:default, :development)添加到maker.gemspec时(如guide to create the gem中所示)

lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "maker/version"
Bundler.require(:default, :development)

我收到如下错误:

[!] There was an error parsing `Gemfile`:  - [!] There was an error while loading `maker.gemspec`:  - [!] There was an error parsing `Gemfile`:  - [!] There was an error while loading `maker.gemspec`:  - [!] There was an error parsing `Gemfile`:

我不确定我在这里可能缺少什么。任何关于我需要做什么才能修复的建议都会非常有用。

谢谢。

1 个答案:

答案 0 :(得分:0)

此问题的答案是使用此帖中提到的bundle console - http://wsmoak.net/2016/07/10/ruby-gem-dev-irb.html