Module: Pragma::Operation::Validation::ClassMethods

Defined in:
lib/pragma/operation/validation.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#contract(klass = nil) { ... } ⇒ Object

Sets the contract to use for validating this operation.

Parameters:

  • klass (Class) (defaults to: nil)

    a subclass of Pragma::Contract::Base

Yields:

  • A block which will be called with the operation’s context which should return the contract class. The block can also return nil if validation should be skipped.



20
21
22
23
24
25
26
# File 'lib/pragma/operation/validation.rb', line 20

def contract(klass = nil, &block)
  if !klass && !block_given?
    fail ArgumentError, 'You must pass either a contract class or a block'
  end

  @contract = klass || block
end

#contract_klassClass|Proc

Returns the contract class.

Returns:

  • (Class|Proc)


31
32
33
# File 'lib/pragma/operation/validation.rb', line 31

def contract_klass
  @contract
end