lib/bumbler/hooks.rb in bumbler-0.6.0 vs lib/bumbler/hooks.rb in bumbler-0.7.0
- old
+ new
@@ -3,10 +3,16 @@
module Hooks
@slow_threshold = 100.0
@started_items = {}
@slow_requires = {}
+ module RequireLogger
+ def require(path, *args)
+ ::Bumbler::Hooks.handle_require(path) { super }
+ end
+ end
+
# Everything's a class method (we're a singleton)
class << self
attr_writer :slow_threshold
attr_reader :slow_requires
@@ -14,26 +20,11 @@
# Inject our custom handling of require into the Kernel.
def hook_require!
@hooking_require = true
# There are two independent require methods. Joy!
- ::Kernel.module_eval do
- class << self
- orig_public_require = Kernel.public_method(:require)
- define_method(:require) do |path, *args|
- ::Bumbler::Hooks.handle_require(path) do
- orig_public_require.call(path, *args)
- end
- end
- end
-
- orig_instance_require = instance_method(:require)
- define_method(:require) do |path, *args|
- ::Bumbler::Hooks.handle_require(path) do
- orig_instance_require.bind(self).call(path, *args)
- end
- end
- end
+ ::Kernel.prepend RequireLogger
+ (class << ::Kernel; self; end).prepend RequireLogger
@hooking_require = nil
end
# Even better: Other gems hook require as well. The instance method one at least.