Class: Toolchain::Validations::Validators::Acceptance

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

Overview

Validates the acceptance of an attribute. Accepted values are as follows: ‘true`, `1` and `“1”`.

Examples:

class User::Creator
  validates :terms, acceptance: {
    message: "the terms of service must be accepted"
  }
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/acceptance.rb', line 15

def validate
  errors.add(key_path, message || "must be accepted") if not_accepted?
end