module ExceptionSwallower::ClassMethods
Public Instance Methods
handle_class_method_exceptions(method_name)
click to toggle source
# File lib/exception_swallower.rb, line 22 def handle_class_method_exceptions(method_name) swallowed_exceptions = self.singleton_class.instance_variable_get("@swallowed_exceptions") return if swallowed_exceptions.nil? old_method = method(method_name) @ignoring_added_methods = true define_singleton_method(method_name) do |*args, &block| begin old_method.call(*args, &block) rescue *swallowed_exceptions; end end @ignoring_added_methods = false end
handle_instance_method_exceptions(method_name)
click to toggle source
# File lib/exception_swallower.rb, line 37 def handle_instance_method_exceptions(method_name) swallowed_exceptions = self.singleton_class.instance_variable_get("@swallowed_exceptions") return if swallowed_exceptions.nil? old_method = instance_method(method_name) @ignoring_added_methods = true define_method(method_name) do |*args, &block| begin old_method.bind(self).call(*args, &block) rescue *swallowed_exceptions; end end @ignoring_added_methods = false end
method_added(method_name)
click to toggle source
Calls superclass method
# File lib/exception_swallower.rb, line 17 def method_added(method_name) super handle_instance_method_exceptions(method_name) unless @ignoring_added_methods end
singleton_method_added(method_name)
click to toggle source
Calls superclass method
# File lib/exception_swallower.rb, line 12 def singleton_method_added(method_name) super handle_class_method_exceptions(method_name) unless @ignoring_added_methods end
swallow_exceptions(*exceptions)
click to toggle source
# File lib/exception_swallower.rb, line 8 def swallow_exceptions(*exceptions) self.singleton_class.instance_variable_set("@swallowed_exceptions", exceptions) end