2017-02-15 45 views
0

我使用bundler創建了gem,並根據文檔建議將所有ruby文件放入'/ lib'。 但我有一個問題,搭建後的寶石,其「Rake構建」命令並安裝(創業板安裝PKG/GEM),因爲我不能用它:在寶石中的要求不起作用

LoadError: cannot load such file -- mygem/client

這是導致因爲在主文件我嘗試需要 'mygem/client.rb' 這是在LIB/mygem/client.rb ,它是不工作:/

這是我gemspec:

# coding: utf-8 
lib = File.expand_path('../lib', __FILE__) 
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 
require 'diggy/version' 

Gem::Specification.new do |spec| 
    spec.name   = "diggy" 
    spec.version  = Diggy::VERSION 
    spec.authors  = [""] 
    spec.email   = [""] 

    spec.summary  = %q{: Write a short summary, because Rubygems requires one.} 
    spec.description = %q{: Write a longer description or delete this line.} 
    spec.homepage  = "" 

    # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host' 
    # to allow pushing to a single host or delete this section to allow pushing to any host. 
    if spec.respond_to?(:metadata) 
    spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'" 
    else 
    raise "RubyGems 2.0 or newer is required to protect against " \ 
     "public gem pushes." 
    end 

    spec.files   = `git ls-files -z`.split("\x0") 
    spec.bindir  = "exe" 
    spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } 
    spec.require_paths = ["lib"] 

    spec.add_development_dependency "bundler", "~> 1.14" 
    spec.add_development_dependency "rake", "~> 10.0" 
end 
+0

您可以添加命令'gem contents mygem'(本例中爲'gem contents diggy')的結果,以及'git status'(從您的gems開發目錄中)。 – matt

回答

0

假設你的主文件名爲mygem.rb,並在lib f年紀大了,你應該能夠要求的文件lib/mygem/client.rb有:

require 'mygem/client' 

注意,我沒有使用.rb擴展。