Class: ActiveInterface::Contract
- Inherits:
-
Object
- Object
- ActiveInterface::Contract
- Defined in:
- lib/active_interface/contract.rb
Instance Method Summary collapse
- #call(&block) ⇒ Object
- #enforce_input(value_name, options) ⇒ Object
- #enforce_output(options) ⇒ Object
-
#initialize(_binding, _output = nil) ⇒ Contract
constructor
A new instance of Contract.
- #output ⇒ Object
- #verify(attribute, interface, value, options = {}) ⇒ Object
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, ) callee = @_binding.eval("__method__") interface = @_binding.eval("self").method(callee).owner value = @_binding.eval(value_name.to_s) verify(value_name, interface, value, ) end |
#enforce_output(options) ⇒ Object
21 22 23 24 25 |
# File 'lib/active_interface/contract.rb', line 21 def enforce_output() callee = @_binding.eval("__method__") interface = @_binding.eval("self").method(callee).owner verify(:output, interface, output, ) end |
#output ⇒ Object
27 28 29 |
# File 'lib/active_interface/contract.rb', line 27 def output @output ||= @_binding.eval("super") end |