Module: Attestor::Validations::ClassMethods

Included in:
Policy, Attestor::Validations
Defined in:
lib/attestor/validations.rb

Instance Method Summary collapse

Instance Method Details

#validate(name, except: nil, only: nil) ⇒ Attestor::Validators #validate(except: nil, only: nil, &block) ⇒ Attestor::Validators

Uses an instance method or block for validation

Mutates the class by changing its #validators attribute!

Overloads:

  • #validate(name, except: nil, only: nil) ⇒ Attestor::Validators

    Uses the instance method for validation

    Parameters:

    • name (#to_sym)

      The name of the instance method

  • #validate(except: nil, only: nil, &block) ⇒ Attestor::Validators

    Uses the block (in the scope of the instance) for validation

    Parameters:

    • block (Proc)

Parameters:

  • options (Hash)

    a customizable set of options

Returns:

  • (Attestor::Validators)

    the updated list of validators



75
76
77
# File 'lib/attestor/validations.rb', line 75

def validate(*args, &block)
  @validators = validators.add_validator(*args, &block)
end

#validates(name, except: nil, only: nil) ⇒ Attestor::Validators #validates(except: nil, only: nil, &block) ⇒ Attestor::Validators

Delegates a validation to instance method or block

Mutates the class by changing its #validators attribute!

Overloads:

  • #validates(name, except: nil, only: nil) ⇒ Attestor::Validators

    Delegates a validation to instance method

    Parameters:

    • name (#to_sym)

      The name of the instance method that should respond to #validate

  • #validates(except: nil, only: nil, &block) ⇒ Attestor::Validators

    Uses the block (in the scope of the instance) for validation

    Parameters:

    • block (Proc)

      The block that should respond to #validate

Parameters:

  • options (Hash)

    a customizable set of options

Returns:

  • (Attestor::Validators)

    the updated list of validators



99
100
101
# File 'lib/attestor/validations.rb', line 99

def validates(*args, &block)
  @validators = validators.add_delegator(*args, &block)
end

#validatorsAttestor::Validators

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a collection of applied validators

Returns:

  • (Attestor::Validators)


50
51
52
# File 'lib/attestor/validations.rb', line 50

def validators
  @validators ||= Validators.new
end