lib/isolator/adapters/base.rb in isolator-0.8.0 vs lib/isolator/adapters/base.rb in isolator-0.9.0

- old
+ new

@@ -20,36 +20,55 @@ def disabled? @disabled == true end - def notify(backtrace, obj, *args) - return unless notify?(*args) - Isolator.notify(exception: build_exception(obj, args), backtrace: backtrace) + def notify(backtrace, obj, *args, **kwargs) + return unless notify?(*args, **kwargs) + Isolator.notify(exception: build_exception(obj, args, kwargs), backtrace: backtrace) end - def notify?(*args) - enabled? && Isolator.enabled? && Isolator.within_transaction? && !ignored?(*args) + def notify?(*args, **kwargs) + enabled? && Isolator.enabled? && Isolator.within_transaction? && !ignored?(*args, **kwargs) end def ignore_if(&block) ignores << block end def ignores @ignores ||= [] end - def ignored?(*args) - ignores.any? { |block| block.call(*args) } + def ignored?(*args, **kwargs) + ignores.any? { |block| block.call(*args, **kwargs) } end private - def build_exception(obj, args) + def build_exception(obj, args, kwargs = {}) klass = exception_class || Isolator::UnsafeOperationError - details = details_message.call(obj, args) if details_message + details = build_details(obj, args, kwargs) klass.new(exception_message, details: details) + end + + def build_details(obj, args, kwargs) + return nil unless details_message + + case details_message.arity + when 2, -2 + # Older users of details_message expected only two arguments. Add + # kwargs hash as last argument, like in older Ruby. + details_message.call(obj, args + [kwargs]) + when 3, -3 + # New signature separates args from kwargs + details_message.call(obj, args, kwargs) + when 1 + # Callback does not care about any args + details_message.call(obj) + else + raise "Unexpected arity (#{details_message.arity}) for #{details_message.inspect}" + end end end end end