Custom Gem execution fails with NoMethodError

自闭症网瘾萝莉.ら 提交于 2019-12-24 11:27:44

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!