Class: ActiveModel::Validations::AcceptanceValidator

Inherits:
EachValidator show all
Defined in:
activemodel/lib/active_model/validations/acceptance.rb

Overview

:nodoc:

Defined Under Namespace

Classes: LazilyDefineAttributes

Instance Attribute Summary

Attributes inherited from EachValidator

#attributes

Attributes inherited from ActiveModel::Validator

#options

Instance Method Summary collapse

Methods inherited from EachValidator

#check_validity!, #validate

Methods inherited from ActiveModel::Validator

kind, #kind, #validate

Constructor Details

#initialize(options) ⇒ AcceptanceValidator

Returns a new instance of AcceptanceValidator.



6
7
8
9
# File 'activemodel/lib/active_model/validations/acceptance.rb', line 6

def initialize(options)
  super({ allow_nil: true, accept: ["1", true] }.merge!(options))
  setup!(options[:class])
end

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



11
12
13
14
15
# File 'activemodel/lib/active_model/validations/acceptance.rb', line 11

def validate_each(record, attribute, value)
  unless acceptable_option?(value)
    record.errors.add(attribute, :accepted, **options.except(:accept, :allow_nil))
  end
end