Skip to content

Commit

Permalink
+ Added Specification.all=. If you use this, we will light you on fire.
Browse files Browse the repository at this point in the history
+ Added Gem.pre_reset_hook/s and post_reset_hook/s.
  • Loading branch information
zenspider committed Apr 27, 2011
1 parent 1f37206 commit 09e026c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
29 changes: 28 additions & 1 deletion lib/rubygems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ class LoadError < ::LoadError
@post_uninstall_hooks ||= []
@pre_uninstall_hooks ||= []
@pre_install_hooks ||= []
@pre_reset_hooks ||= []
@post_reset_hooks ||= []

##
# Try to activate a gem containing +path+. Returns true if
Expand Down Expand Up @@ -719,6 +721,14 @@ def self.post_install(&hook)
@post_install_hooks << hook
end

##
# Adds a hook that will get run after Gem::Specification.reset is
# run.

def self.post_reset(&hook)
@post_reset_hooks << hook
end

##
# Adds a post-uninstall hook that will be passed a Gem::Uninstaller instance
# and the spec that was uninstalled when Gem::Uninstaller#uninstall is
Expand All @@ -737,6 +747,14 @@ def self.pre_install(&hook)
@pre_install_hooks << hook
end

##
# Adds a hook that will get run before Gem::Specification.reset is
# run.

def self.pre_reset(&hook)
@pre_reset_hooks << hook
end

##
# Adds a pre-uninstall hook that will be passed an Gem::Uninstaller instance
# and the spec that will be uninstalled when Gem::Uninstaller#uninstall is
Expand Down Expand Up @@ -1077,6 +1095,11 @@ class << self

attr_reader :post_install_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
Expand All @@ -1088,11 +1111,15 @@ class << self

attr_reader :pre_install_hooks

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

attr_reader :pre_reset_hooks

##
# The list of hooks to be run after Gem::Uninstall#uninstall is finished

attr_reader :pre_uninstall_hooks

end

def self.cache # :nodoc:
Expand Down
22 changes: 17 additions & 5 deletions lib/rubygems/specification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1641,7 +1641,9 @@ def self.reset
# from = caller.first(10).reject { |s| s =~ /minitest/ }
# warn ""
# warn "NOTE: Specification.reset from #{from.inspect}"
Gem.pre_reset_hooks.each { |hook| hook.call }
@@all = nil
Gem.post_reset_hooks.each { |hook| hook.call }
end

extend Enumerable
Expand All @@ -1667,6 +1669,21 @@ def self.dirs
}
end

##
# Sets the known specs to +specs+. Not guaranteed to work for you in
# the future. Use at your own risk. Caveat emptor. Doomy doom doom.
# Etc etc.

def self.all= specs
@@all = specs
end

def self.all
warn "NOTE: Specification.all called from #{caller.first}" unless
Deprecate.skip
_all
end

def self._all
unless defined?(@@all) && @@all then
@@all = self.dirs.reverse.map { |dir|
Expand All @@ -1687,11 +1704,6 @@ def self._resort!
}
end

def self.all
warn "NOTE: Specification.all called from #{caller.first}" unless Deprecate.skip
_all
end

def self.find_by_path path
self.find { |spec|
spec.contains_requirable_file? path
Expand Down

0 comments on commit 09e026c

Please sign in to comment.