Class: Quby::AttributeValidValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/active_model_modules/attribute_valid_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



2
3
4
5
6
7
8
9
# File 'lib/active_model_modules/attribute_valid_validator.rb', line 2

def validate_each(record, attribute, value)
  return if value.blank?
  if value.respond_to?(:valid?)
    record.errors.add(attribute, value.errors.full_messages.join(', ')) unless value.valid?
  else
    record.errors.add(attribute, 'does not respond_to valid?')
  end
end