Cookbook lib requiring gem

Hi,

What’s the appropriate way to require a non-standard gem for a cookbook’s library? I’m adding a zip.rb library to my cookbook, but it requires ‘archive/zip’ to do the actual work.

Should manually installing that gem be a pre-requisite, or is there a clever way to bootstrap it with the gem_package resource in the recipe that uses it?

Or, is relying on extra gems frowned upon?

Thanks for any hints,
Andreas

Check this post from opscode blog where it explains how to require mysql
library and then using it in the same recipe:

Hope it helps.

Jacobo García López de Araujo
blog: http://robotplaysguitar.com
http://workingwithrails.com/person/13395-jacobo-garc-a

On Wed, Feb 23, 2011 at 7:22 PM, Andreas Kollegger <
andreas.kollegger@neotechnology.com> wrote:

Hi,

What's the appropriate way to require a non-standard gem for a cookbook's
library? I'm adding a zip.rb library to my cookbook, but it requires
'archive/zip' to do the actual work.

Should manually installing that gem be a pre-requisite, or is there a
clever way to bootstrap it with the gem_package resource in the recipe that
uses it?

Or, is relying on extra gems frowned upon?

Thanks for any hints,
Andreas

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello!

On Feb 23, 2011, at 11:22 AM, Andreas Kollegger wrote:

What's the appropriate way to require a non-standard gem for a cookbook's library? I'm adding a zip.rb library to my cookbook, but it requires 'archive/zip' to do the actual work.

Should manually installing that gem be a pre-requisite, or is there a clever way to bootstrap it with the gem_package resource in the recipe that uses it?

Or, is relying on extra gems frowned upon?

Not at all frowned on, and it is an encouraged feature of Chef :). In the recipe:

g = gem_package "archive-zip" do
  action :nothing
end

g.run_action(:install)
require 'rubygems'
Gem.clear_paths
require 'archive/zip'

You can see an example of this in a few of Opscode's cookbooks, such as 'aws':

https://github.com/opscode/cookbooks/blob/master/aws/recipes/default.rb


Opscode, Inc
Joshua Timberman, Technical Evangelist
IRC, Skype, Twitter, Github: jtimberman

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (Darwin)

iEYEARECAAYFAk1lU3UACgkQO97WSdVpzT0+wwCeMwLqaZRpBF7FwmXcLDQK6fW4
FbIAnA+LHcvMP8AXRUuk0ir+NaXL24SO
=StRw
-----END PGP SIGNATURE-----

Perfectly clever. Thanks, guys.

Cheers,
Andreas

On Feb 23, 2011, at 7:35 PM, Joshua Timberman wrote:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello!

On Feb 23, 2011, at 11:22 AM, Andreas Kollegger wrote:

What's the appropriate way to require a non-standard gem for a cookbook's library? I'm adding a zip.rb library to my cookbook, but it requires 'archive/zip' to do the actual work.

Should manually installing that gem be a pre-requisite, or is there a clever way to bootstrap it with the gem_package resource in the recipe that uses it?

Or, is relying on extra gems frowned upon?

Not at all frowned on, and it is an encouraged feature of Chef :). In the recipe:

g = gem_package "archive-zip" do
action :nothing
end

g.run_action(:install)
require 'rubygems'
Gem.clear_paths
require 'archive/zip'

You can see an example of this in a few of Opscode's cookbooks, such as 'aws':

https://github.com/opscode/cookbooks/blob/master/aws/recipes/default.rb


Opscode, Inc
Joshua Timberman, Technical Evangelist
IRC, Skype, Twitter, Github: jtimberman

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (Darwin)

iEYEARECAAYFAk1lU3UACgkQO97WSdVpzT0+wwCeMwLqaZRpBF7FwmXcLDQK6fW4
FbIAnA+LHcvMP8AXRUuk0ir+NaXL24SO
=StRw
-----END PGP SIGNATURE-----