Class: Assent::Validator

Inherits:
Object
  • Object
show all
Includes:
Config, Field, Options
Defined in:
lib/assent/validator.rb

Instance Method Summary collapse

Methods included from Config

add, config, config_file, #initialize

Methods included from Options

included, options

Methods included from Field

#add_field, included

Methods included from ValidationsSet

#add, #validations

Instance Method Details

#errorsObject



17
18
19
# File 'lib/assent/validator.rb', line 17

def errors
  errors_class.errors
end

#errors_classObject



13
14
15
# File 'lib/assent/validator.rb', line 13

def errors_class
  @errors ||= Errors.new
end

#validate(input) ⇒ Object

This validate method will validate the input against the rules. At the end it returns true or false. If the errors are empty, it means the validation passed



23
24
25
26
27
28
29
30
31
32
# File 'lib/assent/validator.rb', line 23

def validate(input)
  @@validations.each do |field, validations|
    value = input[field]
    value = input[field].to_s if value.nil?
    validate = Validate.new(field, value, validations, errors_class)
    validate.validate
  end

  errors.empty?
end