How to install uuid4r using homebrew, rvm and bundle

So, I just ran into the problem of installing the uuid4r gem while setting up my development environment for a Rails app. 

While running `bundle install`, I was getting this error:

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /Users/miguel.parramon/.rvm/rubies/ruby-1.9.3-p392/bin/ruby extconf.rb
checking for uuid_export() in -luuid... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more details.  You may need configuration options.

Provided configuration options:
OSSP uuid library 'uuid' required -- not found.

Gem files will remain installed in /Users/miguel.parramon/.rvm/gems/ruby-1.9.3-p392@payments_gemset/gems/uuid4r-0.1.2 for inspection.
Results logged to /Users/miguel.parramon/.rvm/gems/ruby-1.9.3-p392@payments_gemset/gems/uuid4r-0.1.2/ext/gem_make.out

So, first of all, I installed the `ossp-uuid` formula with Homebrew:

brew install ossp-uuid

Homebrew installed the formula correctly, but since it is a keg-only formula, it gave me a warning like this one:

This formula is keg-only, so it was not symlinked into /usr/local.

Mac OS X already provides this program and installing another version in parallel can cause all kinds of trouble.

Generally there are no consequences of this for you.
If you build your own software and it requires this formula, you'll need to add its lib & include paths to your build variables:

    LDFLAGS  -L/usr/local/Cellar/libxslt/1.1.26/lib
    CPPFLAGS -I/usr/local/Cellar/libxslt/1.1.26/include

Then, I used the paths in that warning, together with the provided configuration options suggested by `extconf.rb`, to construct this line:

bundle config build.uuid4r --with-opt-include=/usr/local/opt/ossp-uuid/include --with-opt-lib=/usr/local/opt/ossp-uuid/lib

Which instructs bundler to pass those paths to `extconf.rb` when building the native extension for the `uuid4r` gem. I got the idea from here.

Then I ran:


And it worked! The `uuid4r` gem was installed correctly :D