Method: Handshake::Proxy#method_missing
- Defined in:
- lib/handshake.rb
#method_missing ⇒ Object
Override the send method, and alias method_missing to same. This method intercepts all method calls and runs them through the contract filter. The order of contract checks is as follows:
-
Before: invariants, method signature, precondition
-
Method is called
-
After: method signature, postcondition, invariants
550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 |
# File 'lib/handshake.rb', line 550 def send(meth_name, *args, &block) meth_string = "#{@proxied.class}##{meth_name}" contract = @proxied.class.contract_for(meth_name) return_val = nil # Use throw/catch rather than raise/rescue in order to pull exceptions # once and only once from within the stack trace. Handshake.catch_contract("Contract violated in call to #{meth_string}") do @proxied.check_invariants! contract.check_accepts!(*args, &block) contract.check_pre! @proxied, *args end # make actual call, wrapping the given block in a new block so that # contract checks work if receiver uses yield. return_val = nil if contract.expects_block? cp = CheckedProc.new(contract.block_contract, &block) return_val = @proxied.send(meth_name, *args) { |*argz| cp.call(*argz) } else return_val = @proxied.send(meth_name, *args, &block) end Handshake.catch_contract("Contract violated by #{meth_string}") do contract.check_returns! return_val contract.check_post! @proxied, *(args << return_val) @proxied.check_invariants! end return return_val end |