mygem
私は、CLI ツールとして使用される実行可能ファイルを持つgem を呼び出し ます。
ファイルmygem/bin/mygem
:
#!/usr/bin/env ruby
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'bundler/setup'
....code goes here....
mygem.gemspec
:
Gem::Specification.new do |gem|
gem.bindir = 'bin'
gem.executables = ['mygem']
end
ビルドしてインストールします。
gem build mygem.gemspec
gem install mygem-0.1.0.gem
<optionally bundle install, but that won't fix the error>
そして最後にmygem
、コマンド ラインから正常に呼び出すことができ、スクリプトが実行されます。
問題は、.xml ファイルを含まないフォルダーからしか実行できないことGemfile
です。それ以外の場合、システムはエラーを出力します。
WARN: Unresolved specs during Gem::Specification.reset:
json (>= 0)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.
Could not find differ-0.1.2 in any of the sources
Run `bundle install` to install missing gems.
このエラー メッセージに表示される実際の gem は、現在のディレクトリの Gemfile によって異なります。
実行bundle exec mygem
すると、エラー メッセージの一部が抑制されますが、他のアプリケーションの Gemfilebundle install
で実行されない限り、実行に失敗します。
Could not find differ-0.1.2 in any of the sources
Run `bundle install` to install missing gems.
これはどのように修正できますか?