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) klass.include(LazilyDefineAttributes.new(AttributeDefinition.new(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