2013-01-18 18 views

回答

1

RubyGems本身不會讓你這樣做,可能出於安全原因。 The most you can do is print a message to the user

Gem::Specification.new 'your_gem' do |specification| 
    # ... 

    specification.post_install_message = 'Thanks for installing!' 
end 

什麼你可以做的是包括一個安裝腳本與你的寶石,並要求用戶運行它。使用安裝後消息讓他知道他必須運行該腳本。

3

當安裝了gem時,你不應該能夠運行任意腳本,但是你可以用它來解決這個問題。 RubyGems允許你使用extconf.rb爲你的gem構建擴展,並且可以誘騙它以這種方式運行你的腳本。這裏有一個指南:http://blog.costan.us/2008/11/post-install-post-update-scripts-for.html

有關運行腳本作爲安裝gem的一部分的原因的討論未包含在RubyGems中並且不鼓勵,請按照下面的請求註釋:https://github.com/rubygems/rubygems/pull/213

相關問題