Execute Ruby code after Gem is installed

  • Thread starter Bryan Richardson
  • Start date

B

Bryan Richardson

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?
 
Ad

Advertisements

L

Luis Lavena

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:

https://github.com/iconara/pangolin/blob/master/Rakefile#L8-26

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

https://github.com/iconara/pangolin/blob/master/pangolin.gemspec#L15

Hope that helps you.
 
B

Bryan Richardson

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?
 
E

Eric Hodel

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?

Currently the following extension types are supported in RubyGems:

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

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top