module DebugLogging::Hooks::ClassMethods
Public Instance Methods
debug_after(*names, &blk)
click to toggle source
# File lib/debug_logging/hooks.rb, line 66 def debug_after(*names, &blk) unless blk raise NoBlockGiven, '.after must be called with a block', caller end names.each do |name| meth = instance_method(name) define_method name do |*args, &block| result = meth.bind(self).call(*args, &block) instance_exec(result, &blk) end end end
debug_before(*names, &blk)
click to toggle source
# File lib/debug_logging/hooks.rb, line 51 def debug_before(*names, &blk) unless blk raise NoBlockGiven, '.before must be called with a block', caller end names.each do |name| meth = instance_method(name) define_method name do |*args, &block| instance_exec(name, *args, block, &blk) meth.bind(self).call(*args, &block) end end end
debug_rescue_on_fail(*names, &blk)
click to toggle source
# File lib/debug_logging/hooks.rb, line 33 def debug_rescue_on_fail(*names, &blk) unless blk raise NoBlockGiven, '.rescue_on_fail must be called with a block', caller end names.each do |name| meth = instance_method(name) define_method(name) do |*args, &block| begin meth.bind(self).call(*args, &block) rescue StandardError => e instance_exec(e, &blk) end end end end
debug_time_box(time, *names, &blk)
click to toggle source
# File lib/debug_logging/hooks.rb, line 15 def debug_time_box(time, *names, &blk) names.each do |name| meth = instance_method(name) define_method(name) do |*args, &block| begin Timeout.timeout(time) do meth.bind(self).call(*args, &block) end rescue Timeout::Error error_args = [TimeoutError, 'execution expired', caller] raise(*error_args) unless blk instance_exec(*error_args, &blk) end end end end