examples/exception_handler.rb in aspector-0.13.1 vs examples/exception_handler.rb in aspector-0.14.0

- old
+ new

@@ -1,36 +1,28 @@ -class A +$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) +require 'aspector' - def test input +# Example class to which we will apply our aspects +class ExampleClass + def test(input) puts input.upcase end - end -############################## - -$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) - -require 'aspector' - +# Aspect used to handle exceptions class ExceptionHandler < Aspector::Base - target do - def handle_exception proxy, *args, &block - proxy.call *args, &block + def handle_exception(proxy, *args, &block) + proxy.call(*args, &block) rescue => e puts "Rescued: #{e}" end end around :handle_exception - end -############################## +ExceptionHandler.apply(ExampleClass, method: :test) -ExceptionHandler.apply A, :method => "test" - -a = A.new -a.test 'good' -a.test nil - +a = ExampleClass.new +a.test('good') +a.test(nil)