My library uses a Gem that loads libraries dynamically. For example, it loads 'sqlite3' if I choose an sqlite adapter.
The problem is, if I write in my library
require 'bundler'
Bundler.setup
it stops seeing the gems installed with rubygems and only sees the ones that are installed for this particular lib using Bundler. Thus
require 'sqlite3'
causes an Exception:
`require': LoadError: cannot load such file -- sqlite3
Is there a way to fix this without adding sqlite3 into my own Gemfile?
I should point out, this problem has nothing to do with sqlite3, it seems, but rather with Bundler behavior. sqlite3 was chosen simply because that was the gem that I required that helped me discover this problem.
When you use Bundler.setup it explicitly changes your load path so you only use the gems specified in your Gemfile. It's a desired behaviour to ensure you do not use anything you didn't specify in your Gemfile and to prevent unexpected dependency conflicts.
when dynamically loading gems you should use the require false option:
gem "sqlite3", :require => falseThis will cause bundler to install sqlite3 but only require it when needed.
See Bundler Gemfile manual