我有一个标准的gem scaffold,在bin目录中有一个简单的可执行文件(bin/do_things.rb):
#!/usr/bin/env ruby
require 'my_gem'
MyGem::doThings()gem还没有通过gem install安装,所以在没有bundle exec的情况下运行bin/do_things.rb会失败(我的Gemfile中有gemspec行)。
有没有一种简单的方法让rubygems-bundler在bundler上下文中执行我的脚本?我应该只修改我的可执行文件中的$LOAD_PATH吗?
我也可以创建一个在Bundler下执行的包装器脚本,但我更喜欢使用rubygems-bundler。
或者我应该直接输入bundle exec
发布于 2013-05-27 12:48:38
尝试:
bundle exec bash -l它会让你进入bundler上下文--它是一个额外的外壳,所以运行exit会让你回到没有bundler的上下文。
发布于 2013-05-27 03:56:27
更改文件权限
chmod a+x bin/do_things.rb并解析bin路径,忽略符号链接
require "pathname"
bin_file = Pathname.new(__FILE__).realpathpost,将self添加到libpath
$:.unshift File.expand_path("../../lib", bin_file)发布于 2013-05-27 04:27:24
通过bundle install --binstubs生成二进制存根将为我的gemspec中列出的所有可执行文件创建一个包装器脚本。
#!/usr/bin/env ruby
#
# This file was generated by Bundler.
#
# The application 'do_things.rb' 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)
require 'rubygems'
require 'bundler/setup'
load Gem.bin_path('my_gem', 'do_things.rb')但是,默认情况下,二进制存根路径为bin,这与gem的可执行文件路径冲突,并将覆盖bin中的文件。
运行bundle install --binstubs=SOME_DIR,然后将SOME_DIR添加到.gitignore似乎是最易维护的方法。
然后,我可以简单地执行SOME_DIR/do_things或任何其他项目特定的可执行文件。
https://stackoverflow.com/questions/16762914
复制相似问题