Class: Toolchain::Validations::Validators::Presence

Inherits:
Base
  • Object
show all
Defined in:
lib/toolchain/validations/validators/presence.rb

Overview

Validates the presence of an attribute. If the attribute is either ‘nil` or `“”` (empty String) it is considered invalid.

Examples:

class User::Creator
  validates :name, presence: {
    message: "is required"
  }
end

Instance Attribute Summary

Attributes inherited from Base

#data, #errors, #key_path, #message, #object

Instance Method Summary collapse

Methods inherited from Base

#initialize, #value

Constructor Details

This class inherits a constructor from Toolchain::Validations::Validators::Base

Instance Method Details

#validateObject



15
16
17
# File 'lib/toolchain/validations/validators/presence.rb', line 15

def validate
  errors.add(key_path, message || "can't be blank") if blank?
end