Skip to content

Commit

Permalink
- Add post-installs hooks that runs after Gem::DependencyInstaller fi…
Browse files Browse the repository at this point in the history
…nishes installing a set of gems

- Fix documentation for the various hooks collections
  • Loading branch information
drbrain committed Jun 3, 2011
1 parent 007bf7c commit 7f0607d
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 7 deletions.
30 changes: 23 additions & 7 deletions lib/rubygems.rb
Expand Up @@ -736,6 +736,14 @@ def self.post_install(&hook)
@post_install_hooks << hook
end

##
# Adds a post-installs hook that will be passed a list of installed gem
# specifications when Gem::DependencyInstaller#install is complete

def self.post_installs(&hook)
@post_installs_hooks << hook
end

##
# Adds a hook that will get run after Gem::Specification.reset is
# run.
Expand Down Expand Up @@ -1101,29 +1109,36 @@ class << self
attr_reader :loaded_specs

##
# The list of hooks to be run before Gem::Install#install finishes
# installation
# The list of hooks to be run after Gem::Installer#install extracts files
# and builds extensions

attr_reader :post_build_hooks

##
# The list of hooks to be run before Gem::Install#install does any work
# The list of hooks to be run after Gem::Installer#install completes
# installation

attr_reader :post_install_hooks

##
# The list of hooks to be run after Gem::DependencyInstaller installs a
# set of gems

attr_reader :post_installs_hooks

##
# The list of hooks to be run after Gem::Specification.reset is run.

attr_reader :post_reset_hooks

##
# The list of hooks to be run before Gem::Uninstall#uninstall does any
# work
# The list of hooks to be run after Gem::Uninstaller#uninstall completes
# installation

attr_reader :post_uninstall_hooks

##
# The list of hooks to be run after Gem::Install#install is finished
# The list of hooks to be run before Gem::Installer#install does any work

attr_reader :pre_install_hooks

Expand All @@ -1133,7 +1148,8 @@ class << self
attr_reader :pre_reset_hooks

##
# The list of hooks to be run after Gem::Uninstall#uninstall is finished
# The list of hooks to be run before Gem::Uninstaller#uninstall does any
# work

attr_reader :pre_uninstall_hooks
end
Expand Down
1 change: 1 addition & 0 deletions lib/rubygems/defaults.rb
Expand Up @@ -3,6 +3,7 @@ module Gem
# TODO: move this whole file back into rubygems.rb

@post_install_hooks ||= []
@post_installs_hooks ||= []
@post_uninstall_hooks ||= []
@pre_uninstall_hooks ||= []
@pre_install_hooks ||= []
Expand Down
4 changes: 4 additions & 0 deletions lib/rubygems/dependency_installer.rb
Expand Up @@ -336,6 +336,10 @@ def install dep_or_name, version = Gem::Requirement.default
@installed_gems << spec
end

Gem.post_installs_hooks.each do |hook|
hook.call @installed_gems
end

@installed_gems
end
end
1 change: 1 addition & 0 deletions lib/rubygems/test_case.rb
Expand Up @@ -180,6 +180,7 @@ def setup
# TODO: move to installer test cases
Gem.post_build_hooks.clear
Gem.post_install_hooks.clear
Gem.post_installs_hooks.clear
Gem.post_reset_hooks.clear
Gem.post_uninstall_hooks.clear
Gem.pre_install_hooks.clear
Expand Down
8 changes: 8 additions & 0 deletions test/rubygems/test_gem.rb
Expand Up @@ -944,6 +944,14 @@ def test_self_post_install
assert_equal 2, Gem.post_install_hooks.length
end

def test_self_post_installs
assert_empty Gem.post_installs_hooks

Gem.post_installs do |gems| end

assert_equal 1, Gem.post_installs_hooks.length
end

def test_self_post_reset
assert_empty Gem.post_reset_hooks

Expand Down
8 changes: 8 additions & 0 deletions test/rubygems/test_gem_dependency_installer.rb
Expand Up @@ -155,6 +155,12 @@ def test_install_dependencies_satisfied

def test_install_dependency
util_setup_gems
post_installs_ran = false

Gem.post_installs do |gems|
post_installs_ran = true
assert_equal [@a1, @b1], gems
end

FileUtils.mv @a1_gem, @tempdir
FileUtils.mv @b1_gem, @tempdir
Expand All @@ -166,6 +172,8 @@ def test_install_dependency
end

assert_equal %w[a-1 b-1], inst.installed_gems.map { |s| s.full_name }

assert post_installs_ran, 'post installs hook was not run'
end

def test_install_dependency_development
Expand Down

0 comments on commit 7f0607d

Please sign in to comment.