I have a gem which needs some rake task to be executed after installation of the gem. There is a hackish way to execute a code after install using method described at http://blog.costan.us/2008/11/post-install-post-update-scripts-for.html.
However Gem class now has hooks, and one of them is a post_install hook. I am trying to add a line like
Gem.post_install { puts 'post hook example' }
into Rakefile and it does not seem to be executed during install. Where should this line to be placed for the hook to be registered?
Create a file at lib/rubygems_plugin.rb
In this file you can define your custom hooks. For example:
Gem.post_install do
puts "post_install called for gem"
end
No need to require anything.
Example output:
Successfully built RubyGem
Name: post_install_test
Version: 0.1.0
File: post_install_test-0.1.0.gem
post_install called for gem
Successfully installed post_install_test-0.1.0
1 gem installed
I only found the documentation for this in the source.
If this doesn't work, or your changes to your post install hook don't always seem to update, uninstall the gem completely before rebuilding and installing it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With