wycats / bundler

407 stars 30 forks source link

require_as should respect false to mean "don't require" #126

Closed richievos closed 14 years ago

richievos commented 14 years ago

The rails bundler has the nice behavior where when you specify a gem dependency you can say :lib => false. This tells the installer to not try and require that gem at boot.

This is important for me since some gems insert behavior I want to opt-in to, not have automatically applied during the app's initialization.

I think this just will require a couple lines to change some options[:require_as] to options.has_key?(:require_as).

richievos commented 14 years ago

I've implemented this (with a dependency test) at http://github.com/jerryvos/bundler/tree/require_as_nil

richievos commented 14 years ago

I promised I searched for related issues before adding this, but I couldn't find any. I've now found 2 other duplicates of this:

http://github.com/wycats/bundler/issues/closed/#issue/91 http://github.com/wycats/bundler/issues/closed/#issue/59

I think the :only => :bundle thing is kind of cool, but seems like a mixing of metaphors (no one really has a :bundle environment). Then again :require_as => false seems arbitrary as well, and this implementation makes :require_as => nil behavior differently than :require_as => false, which doesn't follow all ruby conventions.

I'll have to experiment some to see what the total behavior of :only => :bundle means. For instance, given the following situation:

Gemfile

gem 'my_gem', :require_as => false, :only => :bundle

With the :only => :bundle solution, my_gem will not to be downloaded in the following scenario:

first-time deploy

gem bundle --only production
# Some place in the code
require 'my_gem' # explosion since that gem was never downloaded

While in the :require_as => false patch on my branch it would work as desired.

richievos commented 14 years ago

I have updated the tests for this based on the newest code.