我有一个 gem,需要在安装 gem 后执行一些 rake 任务。有一种黑客方法可以在安装后使用以下描述的方法执行代码http://blog.costan.us/2008/11/post-install-post-update-scripts-for.html http://blog.costan.us/2008/11/post-install-post-update-scripts-for.html.
然而 Gem 类现在有钩子,其中之一是 post_install 钩子。我想添加一行像
Gem.post_install { puts 'post hook example' }
到 Rakefile 中,它似乎在安装过程中没有被执行。为了注册钩子,这条线应该放在哪里?
创建一个文件于lib/rubygems_plugin.rb
在此文件中,您可以定义自定义挂钩。例如:
Gem.post_install do
puts "post_install called for gem"
end
不需要要求什么。
输出示例:
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
我只在source https://github.com/rubygems/rubygems/blob/4a778c9c2489745e37bcc2d0a8f12c601a9c517f/lib/rubygems/installer.rb#L22.
如果这不起作用,或者您对安装后挂钩的更改似乎并不总是更新,请在重建和安装之前完全卸载 gem。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)