lib/tailog/watch_methods.rb in tailog-0.4.3 vs lib/tailog/watch_methods.rb in tailog-0.4.5
- old
+ new
@@ -32,10 +32,11 @@
result: true,
error_backtrace: true
}
def inject targets, options = {}
+ WatchMethods.logger.debug "Inject #{targets} with options #{options}."
options = Tailog::WatchMethods.inject_options.merge(options)
targets.each do |target|
begin
if target.include? "#"
inject_instance_method target, options
@@ -49,10 +50,11 @@
end
end
end
def cleanup targets
+ WatchMethods.logger.debug "Cleanup #{targets}."
targets.each do |target|
if target.include? "#"
cleanup_instance_method target
elsif target.include? "."
cleanup_class_method target
@@ -69,9 +71,14 @@
def raw_method? method
method.to_s.start_with? RAW_METHOD_PREFIX
end
def inject_constant target, options
+ unless const_defined? target
+ WatchMethods.logger.error "Inject #{target} FAILED: NameError: uninitialized constant #{target}."
+ return
+ end
+
constant = target.constantize
constant.instance_methods(false).each do |method|
inject_instance_method "#{target}##{method}", options unless raw_method? method
end
constant.methods(false).each do |method|