michaeljbishop / mulligan

Elegant, Ruby-ish Restartable Exceptions for Ruby (like Lisp's "Restarts")
http://michaeljbishop.github.io/mulligan/
MIT License
8 stars 0 forks source link

Changes API to case-syntax #13

Closed michaeljbishop closed 10 years ago

michaeljbishop commented 10 years ago

This is a major api change which results in a simplification of the API. There are only two major functions now:

  1. Kernel#recovery which is used in a case statement to define the recoveries attached to a raised Exception.
  2. Kernel#recover - This used used inside a rescue clause to execute a given recovery.

    C-Extension

The C-extension has been significantly reduced in functionality. It is only needed to provide a hook to ruby code so it can attach the list of captured recoveries. After that, it calls the standard raise method.

Collector

This is used as a trick to collect recoveries. When passed to a case statement, it works in collaboration with the Recovery class by overriding the === method. Instead of actually doing a compare it collects the Recovery onto the collector and returns false. When a recovery is invoked, the code returns to inside that method, only this time it returns true.

Recovery

This is used as the identifier for a Recovery instance attached to an Exception. It is very similar to the Exception class except it is identifying recoveries.

Exception#recoveries

Shows the list of recoveries attached to an exception. This is useful when rescue code is trying ti determine the best recovery to take. Additionally, it can be used in Pry to show the list of recoveries (Exception#recoveries#inspect)