class ActiveModel::Validations::AcceptanceValidator
:nodoc:
def acceptable_option?(value)
def acceptable_option?(value) Array(options[:accept]).include?(value) end
def initialize(options)
def initialize(options) super({ allow_nil: true, accept: ["1", true] }.merge!(options)) setup!(options[:class]) end
def setup!(klass)
def setup!(klass) define_attributes = LazilyDefineAttributes.new(attributes) klass.include(define_attributes) unless klass.included_modules.include?(define_attributes) end
def validate_each(record, attribute, value)
def validate_each(record, attribute, value) unless acceptable_option?(value) record.errors.add(attribute, :accepted, **options.except(:accept, :allow_nil)) end end