Class: ObjectValidator::Checks::Presence

Inherits:
Base
  • Object
show all
Defined in:
lib/object_validator/checks/presence.rb

Instance Attribute Summary

Attributes inherited from Base

#errors, #name, #object, #value

Instance Method Summary collapse

Methods inherited from Base

#initialize, #method

Constructor Details

This class inherits a constructor from ObjectValidator::Checks::Base

Instance Method Details

#callObject



4
5
6
7
8
9
# File 'lib/object_validator/checks/presence.rb', line 4

def call
  presence = !method.nil? || method.respond_to?(:empty?) && !method.empty?
  return if value == presence
  errors.add(name, 'must not be Nil') if value
  errors.add(name, 'must be Nil') unless value
end