Method: Handshake.catch_contract
- Defined in:
- lib/handshake.rb
.catch_contract(mesg = nil, &block) ⇒ Object
Catches any thrown :contract exception raised within the given block, appends the given message to the violation message, and re-raises the exception.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/handshake.rb', line 16 def Handshake.catch_contract(mesg=nil, &block) # :nodoc: violation = catch(:contract, &block) if violation.is_a?(Exception) # Re-raise the violation with the given message, ensuring that the # callback stack begins with the caller of this method rather than # this method. = ( mesg.nil? ? "" : ( mesg + ": " ) ) + violation. raise violation.class, , caller end end |