roqua/quby_engine

View on GitHub
lib/active_model_modules/attribute_valid_validator.rb

Summary

Maintainability
A
25 mins
Test Coverage
class Quby::AttributeValidValidator < ActiveModel::EachValidator
  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
end