我写了一个宝石并安装了它,尽管这个宝石找不到宝石,也不需要'gem_name'
这是我的gemspec
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'faker/faker-rpg/version'
Gem::Specification.new do |spec|
spec.name = "faker-rpg"
spec.version = Faker::Rpg::VERSION
spec.authors = [""]
spec.email = [""]
spec.summary = ""
spec.description = ""
spec.homepage = ""
spec.license = "MIT"
spec.files = `git ls-files -z`.split("\x0")
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]
spec.add_development_dependency "bundler", "~> 1.5"
spec.add_development_dependency "rake"
end
宝石列表找到了宝石
gem list faker-rpg
*** LOCAL GEMS ***
faker-rpg (0.0.1)
它绝对安装在gem文件夹
ls /Users/User/.rvm/gems/ruby-2.0.0-p353/gems/ | grep faker-rpg
faker-rpg-0.0.1
这是上面gems文件夹中的faker-rpg-0.0.1的文件结构
ls -R
Gemfile Rakefile
LICENSE.txt faker-rpg.gemspec
README.md lib
./lib:
faker locales
./lib/faker:
faker-rpg faker-rpg.rb
./lib/faker/faker-rpg:
version.rb
./lib/locales:
faker.en.yml
宝石哪个找不到宝石
gem which faker-rpg
ERROR: Can't find ruby library file or shared library faker-rpg
在ruby控制台中,require不起作用
2.0.0-p353 :001 > require 'faker-rpg'
LoadError: cannot load such file -- faker-rpg
这就是宝石规格faker-rpg给出的内容
gem spec faker-rpg
--- !ruby/object:Gem::Specification
name: faker-rpg
version: !ruby/object:Gem::Version
version: 0.0.1
platform: ruby
authors:
- ''
autorequire:
bindir: bin
cert_chain: []
date: 2014-06-25 00:00:00.000000000 Z
dependencies:
- !ruby/object:Gem::Dependency
name: bundler
requirement: !ruby/object:Gem::Requirement
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '1.5'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '1.5'
- !ruby/object:Gem::Dependency
name: rake
requirement: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
description: ''
email:
- ''
executables: []
extensions: []
extra_rdoc_files: []
files: []
homepage: ''
licenses:
- MIT
metadata: {}
post_install_message:
rdoc_options: []
require_paths:
- lib
required_ruby_version: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
required_rubygems_version: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
requirements: []
rubyforge_project:
rubygems_version: 2.2.2
signing_key:
specification_version: 4
summary: ''
test_files: []
我发现了很多关于此的问题,没有一个被接受的答案解决了我的问题。 我唯一能想到的是gemspec有行'files:[]',但文件肯定是安装在gems文件夹中的gem。
有没有人有想法?
答案 0 :(得分:0)
gem实际安装正确,只是你没有完全正确的lib路径。尝试运行gem which faker/faker-rpg
来查看。
您只需将lib/faker
的内容向上移动一级,以便它们直接位于lib
之下。目前您正在搜索faker-rpg.rb
,但该文件仅作为faker/faker-rpg.rb
存在,因此无法找到。
您可能需要调整其他部分以使其全部工作。您没有提到locales
目录中的内容 - 最好将其移到faker-rpg
目录下。此外,您require
中获得该版本的gemspec
行也需要进行调整。