I want to execute some code during preinstallation when installing gem from rubygems.org using a command like gem install some-gem.
The documentation states that you can use http://docs.ruby-lang.org/en/2.2.0/Gem.html hook, which looks like this:
def self.pre_install(&hook)
@pre_install_hooks << hook
end
The rest of the document says:
By default, RubyGems values are stored in rubygems / defaults.rb. If you are wrapping RubyGems or implementing Ruby, you can change the settings of RubyGems. For RubyGems packages, specify lib / rubygems / defaults / operating_system.rb and override any default values from lib / rubygems / defaults.rb. For Ruby developers, specify lib / rubygems / defaults / # {RUBY_ENGINE} .rb and override any default values from lib / rubygems / defaults.rb. If you need RubyGems to do additional installation or removal work , the default override file can install pre and post install and remove the hooks. See :: pre_install, :: pre_uninstall, :: post_install, :: post_uninstall.
Sounds like what I want. So I created the files
- Library / RubyGems / default /defaults.rb
- /RubyGems/ /operating _system.rb
- RubyGems/defaults.rb
Gem.pre_install { puts 'pre install hook called!' }
. require_paths gemspec, :
s.require_paths = ["lib", "test", "rubygems"]
.
?