Class: Handshake::CheckedProc

Inherits:
Proc
  • Object
show all
Defined in:
lib/handshake/block_contract.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(contract, &block) ⇒ CheckedProc

Returns a new instance of CheckedProc.



5
6
7
8
# File 'lib/handshake/block_contract.rb', line 5

def initialize(contract, &block)
  @contract = contract
  super(&block)
end

Instance Attribute Details

#contractObject

Returns the value of attribute contract.



3
4
5
# File 'lib/handshake/block_contract.rb', line 3

def contract
  @contract
end

Instance Method Details

#call(*args) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/handshake/block_contract.rb', line 14

def call(*args)
  Handshake.catch_contract("Contract violated in call to proc #{self}") do
    @contract.check_accepts!(*args)
  end if checked?
  
  return_value = super(*args)
  
  Handshake.catch_contract("Contract violated by proc #{self}") do
    @contract.check_returns! return_value
  end if checked?
  
  return_value
end

#checked?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/handshake/block_contract.rb', line 10

def checked?
  not @contract.nil?
end