Class: Toolchain::Validations::Validators::Length

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

Overview

Validates the lengt of an attribute.

Examples:

class User::Creator
  validates :password, length: {
    between: 5..100,
    message: "must be between 5 and 100 characters long"
  }
end

class User::Creator
  validates :password, length: {
    greater_than: 5,
    less_than 100,
    message: "must be between 5 and 100 characters long"
  }
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



23
24
25
# File 'lib/toolchain/validations/validators/length.rb', line 23

def validate
  errors.add(key_path, message || "is invalid") unless valid?
end