Execute Ruby code after Gem is installed

Hello All,

I'm creating a Ruby gem that utilizes the ruby_protobuf gem to generate
Ruby code using a protocol descriptor file (protocol.proto) in Google
Protobuf's format. Given this, my gem has a dependency for the
ruby_protobuf gem, and I'd like to use rprotoc (provided by
ruby_protobuf) to compile the protocol.proto file in my gem with
whatever version of ruby_protobuf is or gets installed when my gem is
installed.

Can Gem.post_install hooks be used in this case, or should I use the
extensions attribute of a gemspec file to identify code to be executed
after my gem is installed?

If post_install hooks can be used, where should the hooks be defined?

If the extensions attribute can be used, can a .rb file added to the
extensions attribute simply contain random Ruby code, or does it have to
be extconf.rb-style Ruby code in it?

···

--
Thanks!
Bryan

--
Posted via http://www.ruby-forum.com/.

Hello All,

Can Gem.post_install hooks be used in this case, or should I use the
extensions attribute of a gemspec file to identify code to be executed
after my gem is installed?

No, post_install display a message, it doesn't execute code due the
insecure nature of executing code from untrusted sources.

But...

If post_install hooks can be used, where should the hooks be defined?

If the extensions attribute can be used, can a .rb file added to the
extensions attribute simply contain random Ruby code, or does it have to
be extconf.rb-style Ruby code in it?

You can use extconf.rb (Ruby Extensions) in the gem specification to
generate the required files for your gem to work.

Pangolin gem used to do that:

But instead of using extconf.rb now it uses a Rakefile that is
executed as extension:

Hope that helps you.

···

On Jan 6, 1:36 am, Bryan Richardson <btrichard...@gmail.com> wrote:
--
Luis Lavena

Sweet... thanks Luis! I'll try this out. Does the file provided to the
extensions attribute have to be a Rakefile (i.e. is rake used to execute
extension files) or can it be just any Ruby file?

···

--
Posted via http://www.ruby-forum.com/.

Cool... that solved my problem. Thanks again!

···

--
Posted via http://www.ruby-forum.com/.

Currently the following extension types are supported in RubyGems:

configure + make
extconf.rb + make
Rakefile + rake
mkrf_conf.rb + rake

···

On Jan 6, 2011, at 14:29, Bryan Richardson wrote:

Sweet... thanks Luis! I'll try this out. Does the file provided to the
extensions attribute have to be a Rakefile (i.e. is rake used to execute
extension files) or can it be just any Ruby file?