Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute without `bundle exec` via rubygems-bundler

I have a standard gem scaffold, and in inside the bin directory I have a simple executable (bin/do_things.rb):

#!/usr/bin/env ruby
require 'my_gem'
MyGem::doThings()

The gem hasn't been installed via gem install, so running bin/do_things.rb without bundle exec fails (my Gemfile has the gemspec line in it).

Is there a simple way to have rubygems-bundler execute my script in the bundler context? Should I just modify the $LOAD_PATH in my executable instead?

I could create a wrapper script to execute under Bundler as well, but I'd rather leverage rubygems-bundler somehow.

Or should I just type bundle exec?

like image 889
Dan Avatar asked Mar 03 '26 15:03

Dan


2 Answers

try:

bundle exec bash -l

it will set you into bundler context - it's an extra shell so running exit will get you back to bundler less context.

like image 172
mpapis Avatar answered Mar 05 '26 21:03

mpapis


Generating binstubs via bundle install --binstubs creates a wrapper script for all executables listed in my 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')

However, by default, the binstubs path is bin, which conflicts with gem's executable path, and will overwrite files in bin.

Running bundle install --binstubs=SOME_DIR and then adding SOME_DIR to .gitignore seem to be the most maintainable way.

Then, I can simple execute SOME_DIR/do_things or any other project-specific executable I add down the line.

like image 32
Dan Avatar answered Mar 05 '26 20:03

Dan