Ruby 无法加载从git源安装的gem(加载错误:无法加载此类文件)
我已经在monorepo结构中创建了一个名为Ruby 无法加载从git源安装的gem(加载错误:无法加载此类文件),ruby,git,rubygems,bundle,Ruby,Git,Rubygems,Bundle,我已经在monorepo结构中创建了一个名为registry\u client的gem。希望我能在我的前端应用程序内部使用它。但是,当我尝试使用bundlerbundle exec ruby app.rb运行它时,遇到了这个错误: LoadError: cannot load such file -- registry_client 前端应用程序中的文件: source 'https://rubygems.org' gem 'registry_client', git: 'https://g
registry\u client
的gem。希望我能在我的前端应用程序内部使用它。但是,当我尝试使用bundlerbundle exec ruby app.rb运行它时,遇到了这个错误:
LoadError: cannot load such file -- registry_client
前端应用程序中的文件
:
source 'https://rubygems.org'
gem 'registry_client', git: 'https://github.com/.../some_repo.git', branch: 'master', glob: 'registry-client/*.gemspec'
我使用捆绑包列表验证了gem在捆绑包安装后成功安装:
Gems included by the bundle:
...
* registry_client (0.1.1 f93f5bd)
...
这将影响回购结构:
├── frontend-app
│ ├── Gemfile
│ ├── Gemfile.lock
│ ├── Rakefile
│ ├── app.rb
│ ├── config
│ ├── config.ru
│ ├── test
│ └── views
└── registry-client
├── Gemfile
├── lib
├── registry_client.gemspec
└── test
app.rb
require 'registry_client'
...
registry_client.gempec
# frozen_string_literal: true
require_relative 'lib/version'
Gem::Specification.new do |spec|
spec.name = 'registry_client'
spec.summary = 'Registry client for using Redis as Service Registry.'
spec.authors = ['Author']
spec.version = RegistryClient::VERSION
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
spec.files = Dir.chdir(File.expand_path(__dir__)) do
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
end
spec.bindir = 'exe'
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']
end
编辑:添加gempec文件require
方法查看$LOAD\u PATH
中的目录,并尝试查找名称与参数注册表\u客户端
匹配的文件。gempec中的spec.required\u路径
属性指定:
激活此gem时,要添加到$LOAD_PATH的gem中的路径。默认值为“lib”
因此,您的lib
目录必须有一个名为registry\u client
的文件(在您的情况下,它将具有.rb
扩展名)。
这里有更多信息:运行gem环境
,并捕获安装目录
的值。然后将/gems
添加到安装目录,并使用ls
命令列出其内容。你看到你的gem了吗?@PetrGazarov目录中缺少gem,但我相信这可能是bundler文档中的预期行为:注意,因为RubyGems缺乏处理git中gem的能力,所以从git存储库安装的任何gem都不会出现在gem列表中。但是,在运行Bundler.setup之后,它们将可用。
@PetrGazarov这是在bundle info registry_client
下显示的内容:*registry_client(0.1.1 f93f5bd)摘要:将Redis用作服务注册表的注册表客户端。路径:/Users/julianho/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/bundler/gems/service-api-example-impl-f93f5bd49c46/registry-client
当您ls/Users/julianho/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/bundler/gems/service-api-example-impl-f93f5bd49c46/registry-client
时,您是否看到registry\gems.pec>是<代码>总计24 drwxr-xr-x 7 julianho员工224B 3月22日16:13。drwxr-xr-x 10 julianho staff 320B Mar 22 16:13-rw-r--r--1名朱利安霍员工115B Mar 22 16:13 Gemfile-rw-r--r--1名朱利安霍员工270B Mar 22 16:13 Gemfile.lock drwxr-xr-x 6名朱利安霍员工192B Mar 22 16:13 lib-rw-r--r--1名朱利安霍员工832B Mar 22 16:13 registry_client.gempec drwxr-xr-x 3朱利安霍员工96B Mar 22 16:13测试