Giter Club home page Giter Club logo

rbenv-bundle-exec's Introduction

rbenv-bundle-exec: The one true plugin for rbenv bundler integration

This plugin makes rbenv bundle exec your ruby executables so you don't have to.

Unlike other rbenv bundler integration plugins out there, this plugin is extremely simple and uses significantly less code to offer a better solution to the same problem. In fact, don't just take my word for it, go ahead and read the code yourself. The entire project is ~40 lines of code.

Installation

  1. Obviously, before you get this plugin, you should have rbenv up and running.

  2. Clone this repository into your ~/.rbenv/plugins directory:

$ git clone https://github.com/maljub01/rbenv-bundle-exec.git ~/.rbenv/plugins/rbenv-bundle-exec
  1. You should probably also get rbenv-gem-rehash, which, is a plugin that automatically runs rbenv rehash every time you install or uninstall a gem that exposes ruby executables.

Without rbenv-gem-rehash, you'll need to remember to run rbenv rehash every time you use bundle install to install new gems with executables. But seriously, just do yourself a favor and get the plugin, you'll thank yourself for it later.

  1. Never have to run bundle exec ever again!

Usage

This plugin will check if you have bundler installed, if so it will search for a Gemfile in the current directory and its ancestors (up to root). If a Gemfile is found, it will forward whatever ruby executable command you wrote to bundle exec. That's it.

Caveats (Please Read This Before Installing)

Before you install this plugin you need to clearly understand that after installing it, every time you run any ruby executable under any directory that has a Gemfile, this plugin will forward your command to bundle exec. Of course you already knew this. Afterall, you need things to run under bundle exec 90% of the time, and this is probably why you're here in the first place.

This section is meant to point your attention to some use-cases that belong to the remaining 10%, when bundle exec is not what you want, and should help you make sure that rbenv-bundle-exec stays out of the way when you're in such situations.

The reason I think this is so important is that, due to its fully-automated nature, it is extremely easy to completely forget about rbenv-bundle-exec when you try to run a ruby command that shouldn't be run through bundle exec. I will mention here some of the main pitfalls that you might encounter. Hopefully, having read this, you'll escape those pitfalls after a couple of seconds rather than after possibly endless hours.

  1. Running gem:

There aren't many good reasons why anyone would want gem to be always executed using bundle exec by default. What's more, there are so many ways that things could break if you try to run bundle exec gem install. For this reason, The plugin will always ignore gem and not forward its commands to bundle exec.

  1. Running irb:

When you run irb, it will be executed under the context of your current bundle (aka. bundle exec irb). This means that there will be no discrepency between what you see in irb and what your app does due to them using different versions of some gem. However, it also means that requiring gems that don't belong to your bundle will not work unless you run irb with the plugin disabled. If you find yourself wondering why irb is stubbornly refusing to require a gem that you know is installed, try to disable the plugin first before you curse the ghost inside the machine.

If you use pry and have it in your Gemfile, I recommend checking out pry-debundle which would allow you to require gems not in your Gemfile from pry.

  1. Running ruby executables that are not in your project's Gemfile:

Your development workflow might include running executables for static analysis gems or for irb replacements like the awesome pry. Because everyone has their unique set of tools that they like to use, those tools are often not included in the Gemfiles of projects shared between several people. If that's the case, then you'll need to disable the plugin for those tools' commands to be able to run them. Of course if you forget to disable the plugin for some command, bundler will complain that it can't find it, which should remind you of rbenv-bundle-exec and the need to disable it to be able to run that command.

  1. Other cases:

I think I've covered the most common cases. However, that doesn't mean that I've covered them all. If you start getting extremely weird behavior from some of your gems, it's probably wise to try to disable this plugin (and others that might look suspicious) before you go and blame innocent people for my bad code or your bad memory.

Disabling the Plugin

There are several good reasons why you would want to disable the plugin for a certain command. Some of these situations are mentioned in the "Caveats" section above. Regardless of your specific circumstances, there are several ways you could bypass the plugin for a command of your choice:

  1. Setting the environmant variable NO_BUNDLE_EXEC to a non-empty string:
$ NO_BUNDLE_EXEC=1 pry

Running the previous command will bypass rbenv-bundle-exec and run pry and not bundle exec pry. You can of course also use aliases so you won't have to type NO_BUNDLE_EXEC all the time:

$ alias pry='NO_BUNDLE_EXEC=1 pry'
$ pry # All future invokations of pry will run without `bundle exec`
  1. List the commands to be skipped in $HOME/.no_bundle_exec, each on a separate line. For example:
$ echo irb >> ~/.no_bundle_exec
$ echo pry >> ~/.no_bundle_exec

$ irb # All future invokations of irb, pry & other commands added to the .no_bundle_exec file will run without `bundle exec`

Similar plugins

  1. rbenv-binstubs - Provides bundler integration by using binstubs. However, it requires that you manually install bundler binstubs for all of your projects. I don't like that.

  2. rbenv-bundler - Provides bundler integration by adjusting rbenv's shims and the rbenv which command with respect to the current project's bundle. However, its usage is not recommended by rbenv maintainers.

Why use rbenv-bundle-exec instead of the ones listed above

I believe that this plugin offers the best of both worlds; it lets you enjoy the same benefits of fully automated integration that rbenv-bundler provides, without having to settle for less speed or less stability than those provided by rbenv-binstubs.

License

Copyright (c) 2013 Marwan Al Jubeh - Released under the MIT-LICENSE.

rbenv-bundle-exec's People

Contributors

maljub01 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

rbenv-bundle-exec's Issues

how does it interract with rbenv-binstubs?

rails 4+ comes with a few binstubs and it seems to make sense to let rbenv-binstubs to invoke those first (and whatever else one might put there) and then use rbenv-bundle-exec on everything else.

Add release

I'd like to add a Homebrew formula for this plugin, but it doesn't have a release to link against.

For example, I would need something like:

url 'https://github.com/maljub01/rbenv-bundle-exec/archive/v1.0.0.tar.gz'

Currently there is only HEAD to link against:

url 'https://github.com/maljub01/rbenv-bundle-exec/archive/master.zip'

Homebrew requires a stable tarball for standard formulae.

rbenv plugin work

I am reinstalling my rbenv now, all works, but i leave the rbev-bundler pliugin outside.

right now i am testing https://github.com/maljub01/rbenv-bundle-exec and works very well with me.

Ubuntu 14.04
zsh with oh-my-zsh, bundler, and rbenv plugin now installed.

this one works very well, with me, without need for "bundle exec" (i have a 'be' alias in zsh that works very well in any case too)

this plugin have any problem with rbenv core ? i would like to work in this too (if is needed)

bundle install won't work first time

Hi,

When you try to bundle install this plugin should not add bundle exec.
So, if you do:

git clone myproject
cd myproject
bundle install  # it detects Gemfile and really does: bundle exec bundle install (which fails)

This error only happens for new projects that haven't been bundle installed before on the machine, because afterwards bundle exec is capable of finding the gems in Gemfile.lock. But anyways, bundle exec bundle install should never happen.

PD: don't bother to ask if I didn't make myself clear with explanations

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.