Class: UniversalValidator::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/universal_validator/validator.rb

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Validator

Returns a new instance of Validator.

Yields:

  • (_self)

Yield Parameters:



22
23
24
# File 'lib/universal_validator/validator.rb', line 22

def initialize
  yield self if block_given?
end

Instance Method Details

#add_error_for(field, msg) ⇒ Object



34
35
36
37
# File 'lib/universal_validator/validator.rb', line 34

def add_error_for(field, msg)
  errors[field] ||= []
  errors[field] << msg
end

#errorsObject



30
31
32
# File 'lib/universal_validator/validator.rb', line 30

def errors
  @errors ||= {}
end

#errors?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/universal_validator/validator.rb', line 26

def errors?
  errors.count.positive?
end

#errors_for(field) ⇒ Object



39
40
41
# File 'lib/universal_validator/validator.rb', line 39

def errors_for(field)
  errors[field]
end