如何编写一个在安装RubyGem时被调用的钩子? [英] How can I write a hook that gets called when a RubyGem is installed?

查看:76
本文介绍了如何编写一个在安装RubyGem时被调用的钩子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一段Ruby代码片段,当我的Gem首次通过 [sudo] gem install mygem 安装时运行。它可以做到吗?

解决方案

它看起来并不像它真的被支持。我发现了一个post_install_message属性,您应该可以在gem规范中设置,但不会执行代码。

将你的在线代码打包成你的宝石中的扩展(就像它是一个本地扩展),并提供一个Rakefile来构建扩展(即调用你的代码)。

I'd like to write a Ruby snippet that gets run when my Gem is first installed via [sudo ]gem install mygem. Can it be done?

解决方案

It doesn't look like it's really supported. I found a "post_install_message" attribute that you should be able to set in the gem spec, but that won't execute code.

You may be able to do it by packaging your on-install code as an extension in your gem (as if it were a native extension), and providing a Rakefile to "build" the extension (i.e. call your code).

这篇关于如何编写一个在安装RubyGem时被调用的钩子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆