[英]Use ruby gem from git repo via Bundler
I have created a custom gem using bundler and checked it in a git repo. 我使用bundler创建了一个自定义gem并在git repo中检查它。
custom_gem.rb custom_gem.rb
require "custom_gem/version"
require "custom_gem/custom_class"
module CustomGem
# Your code goes here...
end
custom_class.rb custom_class.rb
require 'typhoeus'
module CustomGem
class CustomClass
def self.custom_method
#do stuff with typhoeus
end
end
end
Added it as a dependency to another project and installed it via bundler. 将其作为依赖项添加到另一个项目并通过bundler安装。
gem 'custom_gem', :git => 'git@bitbucket.org:dir/repo.git'
After that I try to use it by calling 之后我尝试通过调用来使用它
CustomGem::CustomClass.custom_method
and I get the following error: 我收到以下错误:
uninitialized constant CustomGem::CustomClass 未初始化的常量CustomGem :: CustomClass
Any suggestions? 有什么建议么?
Might be a small thing but just starting out with ruby so any advice would be great. 可能是一件小事,但刚开始使用红宝石,所以任何建议都会很棒。
Two things to check : 要检查两件事:
The file custom_gem.rb should be in lib/custom_gem.rb , and the file custom_class.rb should be in lib/custom_gem/custom_class.rb 文件custom_gem.rb应位于lib / custom_gem.rb中 ,文件custom_class.rb应位于lib / custom_gem / custom_class.rb中
lib/custom_gem/custom_class.rb
\_/ \________________________/
| |
| \_ comes from your code: `require "custom_gem/custom_class"`
|
|
\_ comes from custom_gem.gempsec (the line `s.require_paths = ["lib"]`)
For more about the load path, file hierarchy and naming, check out this gem guide . 有关加载路径,文件层次结构和命名的更多信息,请查看此gem指南 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.