Class: DuckRecord::Validations::SubsetValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/duck_record/validations/subset.rb

Overview

:nodoc:

Constant Summary collapse

ERROR_MESSAGE =
"An object with the method #include? or a proc, lambda or symbol is required, " \
"and must be supplied as the :in (or :within) option of the configuration hash"

Instance Method Summary collapse

Instance Method Details

#check_validity!Object



9
10
11
12
13
# File 'lib/duck_record/validations/subset.rb', line 9

def check_validity!
  unless delimiter.respond_to?(:include?) || delimiter.respond_to?(:call) || delimiter.respond_to?(:to_sym)
    raise ArgumentError, ERROR_MESSAGE
  end
end

#validate_each(record, attribute, value) ⇒ Object



15
16
17
18
19
# File 'lib/duck_record/validations/subset.rb', line 15

def validate_each(record, attribute, value)
  unless subset?(record, value)
    record.errors.add(attribute, :subset, options.except(:in, :within).merge!(value: value))
  end
end