问题
I've written my first gem (ruby noob alert!). To deploy it into my local gem directory I ran:
bundle install
bundle exec rake install
At this point I try to run my gem from the command line. I get a cryptic error:
my_gem
Gem File Location:
C:/ruby193/lib/ruby/gems/1.9.1/gems/my_gem-0.0.1/Gemfile
fatal: Not a git repository (or any of the parent directories): .git
getting Gem.bin_path()
C:/ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.6.3/lib/bundler/rubygems_integration.rb:305:in `block in replace_bin_path': undefined method `name' for nil:NilClass (NoMethodError)
from C:/ruby193/lib/ruby/gems/1.9.1/gems/my_gem-0.0.1/bin/my_gem:20:in `<top (required)>'
from C:/ruby193/bin/my_gem:23:in `load'
from C:/ruby193/bin/my_gem:23:in `<main>'
When I ran bundle install it replaced the contents of bin/my_gem with it's own code. I did add modify this file slightly trying to debug. The failure seems to happen in Gem.bin_path. Here are the contents of bin/my_gem:
#!/usr/bin/env ruby
#
# This file was generated by Bundler.
#
# The application 'my_gem' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)
puts "Gem File Location: "
puts(ENV['BUNDLE_GEMFILE'])
require 'rubygems'
require 'bundler/setup'
puts "getting Gem.bin_path()"
path = Gem.bin_path('my_gem', 'my_gem') # this is the line that causes the error
puts "Gem.bin_path(): #{path}"
load Gem.bin_path('my_gem', 'my_gem')
I'm at a loss for what to do next other than start over with a fresh gem. Any ideas?
回答1:
It looks like you're running into this issue https://github.com/bundler/bundler/issues/2838
Because Bundler remembers flags passed to install
, if you ever ran bundle install --binstubs
in the past, it will re-generate the binstubs on subsequent runs of bundle install
. You can run bundle config --delete bin
to delete that setting and then restore your original executable file.
来源:https://stackoverflow.com/questions/24833123/custom-gem-execution-fails-with-nomethoderror