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?
views:
229answers:
3
A:
You can try to do this using call of OS commands. I'll quote eample from irb but you can do same in your scripts too.
irb(main):001:0> system 'gem list | grep rails'
rails (2.1.1, 2.1.0)
=> true
irb(main):002:0> system 'gem list | grep railssssss'
=> false
You can use result of this command as the condition of your snippet execution.
IDBD
2008-10-22 15:56:56
+1
A:
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).
Matt Burke
2008-10-23 14:22:03
Great hacking, Victor!
James A. Rosen
2008-11-22 20:10:16