Commit f6377568 authored by Samuel E. Giddins's avatar Samuel E. Giddins

[HooksManager] Show the name of the source for each hook that is run in verbose mode

Huge thanks to @alloy for the `source_location` hint!

The name calculation is wrapped in a lambda so it's not called when it won't be printed out
parent 24d8d491
......@@ -4,6 +4,15 @@ To install or update CocoaPods see this [guide](http://docs.cocoapods.org/guides
To install release candidates run `[sudo] gem install cocoapods --pre`
## Master
##### Enhancements
* Show the name of the source for each hook that is run in verbose mode.
[Samuel Giddins](https://github.com/segiddins)
[#2639](https://github.com/CocoaPods/CocoaPods/issues/2639)
## 0.35.0
[CocoaPods](https://github.com/CocoaPods/CocoaPods/compare/0.34.4...0.35.0)
......
require 'rubygems'
module Pod
# Provides support for the hook system of CocoaPods. The system is designed
# especially for plugins. Interested clients can register to notifications by
......@@ -15,7 +17,7 @@ module Pod
#
module HooksManager
class << self
# @return [Hash{Symbol => Proc}] The list of the blocks that are
# @return [Hash{Symbol => Array<Proc>}] The list of the blocks that are
# registered for each notification name.
#
attr_reader :registrations
......@@ -52,8 +54,21 @@ module Pod
if @registrations
blocks = @registrations[name]
if blocks
blocks.each do |block|
block.call(context)
pretty_name = name.to_s.gsub('_', ' ')
UI.message "- Running #{pretty_name} hooks" do
blocks.each do |block|
gem_name_lambda = lambda do
file, _line = block.source_location
gem_spec = Gem::Specification.find do |spec|
spec.require_paths.find { |f| file.include? File.join(spec.full_gem_path, f) }
end
gem_name = (gem_spec && gem_spec.name) || File.basename(file, '.rb')
end
UI.message "- #{gem_name_lambda.call}" do
block.call(context)
end
end
end
end
end
......
......@@ -60,6 +60,20 @@ module Pod
@hooks_manager.run(:post_install, nil)
end
end
it 'prints a message in verbose mode when any hooks are run' do
config.verbose = true
@hooks_manager.register(:post_install) { |_| }
@hooks_manager.run(:post_install, Object.new)
UI.output.should.match /- Running post install hooks/
end
it 'prints a message in verbose mode for each hook run' do
config.verbose = true
@hooks_manager.register(:post_install) { |_| }
@hooks_manager.run(:post_install, Object.new)
UI.output.should.match /- hooks_manager_spec/
end
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment