Module: Attestor::Validations::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

#follow_policy(name, except: nil, only: nil) ⇒ Attestor::Collection

Registers a followed policy

Mutates the class by changing its #validators attribute!

Parameters:

  • name (#to_sym)
  • [#to_sym, (Hash)

    a customizable set of options

Returns:

  • (Attestor::Collection)

    the updated collection



83
84
85
# File 'lib/attestor/validations.rb', line 83

def follow_policy(*args)
  @validators = validators.add_follower(*args)
end

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

Registers a validator

Mutates the class by changing its #validators attribute!

Parameters:

  • name (#to_sym)
  • options (Hash)

Returns:

  • (Attestor::Validators)

    the updated collection



67
68
69
# File 'lib/attestor/validations.rb', line 67

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

#validate(*args) ⇒ Attestor::Validators

Registers a validator

Mutates the class by changing its #validators attribute!

Parameters:

  • name (#to_sym)
  • options (Hash)

Returns:

  • (Attestor::Validators)

    the updated collection



67
68
69
# File 'lib/attestor/validations.rb', line 67

def validate(*args)
  @validators = validators.add_validator(*args)
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