Class: ActiveInterface::Contract

Inherits:
Object
  • Object
show all
Defined in:
lib/active_interface/contract.rb

Instance Method Summary collapse

Constructor Details

#initialize(_binding, _output = nil) ⇒ Contract

Returns a new instance of Contract.



3
4
5
6
# File 'lib/active_interface/contract.rb', line 3

def initialize(_binding, _output = nil)
 @_binding = _binding
 @output = _output
end

Instance Method Details

#call(&block) ⇒ Object



8
9
10
11
# File 'lib/active_interface/contract.rb', line 8

def call(&block)
 result = block.call self
 output
end

#enforce_input(value_name, options) ⇒ Object



13
14
15
16
17
18
# File 'lib/active_interface/contract.rb', line 13

def enforce_input(value_name, options)
  callee = @_binding.eval("__method__")
  interface = @_binding.eval("self").method(callee).owner
  value = @_binding.eval(value_name.to_s)
  verify(value_name, interface, value, options)
end

#enforce_output(options) ⇒ Object



21
22
23
24
25
# File 'lib/active_interface/contract.rb', line 21

def enforce_output(options)
  callee = @_binding.eval("__method__")
  interface = @_binding.eval("self").method(callee).owner
  verify(:output, interface, output, options)
end

#outputObject



27
28
29
# File 'lib/active_interface/contract.rb', line 27

def output
  @output ||= @_binding.eval("super")
end

#verify(attribute, interface, value, options = {}) ⇒ Object



31
32
33
# File 'lib/active_interface/contract.rb', line 31

def verify(attribute, interface, value, options = {})
  Verify.call(attribute, interface, value, options)
end