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, options = {}) ⇒ Attestor::Collection

Registers a followed policy

Mutates the class by changing its #validators attribute!

Parameters:

  • name (#to_sym)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :except (#to_sym, Array<#to_sym>)

    the black list of contexts for validation

  • :only (#to_sym, Array<#to_sym>)

    the white list of contexts for validation

Returns:

  • (Attestor::Collection)

    the updated collection



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

def follow_policy(name, options = {})
  @validators = validators.add(name, options.merge(policy: true))
end

#validate(name, options = {}) ⇒ Attestor::Validators

Registers a validator

Mutates the class by changing its #validators attribute!

Parameters:

  • name (#to_sym)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :except (#to_sym, Array<#to_sym>)

    the black list of contexts for validation

  • :only (#to_sym, Array<#to_sym>)

    the white list of contexts for validation

Returns:

  • (Attestor::Validators)

    the updated collection



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

def validate(name, options = {})
  @validators = validators.add(name, options)
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