hummingbird-me/kitsu-server

View on GitHub
app/validators/polymorphism_validator.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
class PolymorphismValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, value)
    valid_types = [options[:type]].flatten
    unless valid_types.any? { |type| value.is_a?(type) }
      record.errors.add(attribute, message: (options[:message] || "disallowed type"))
    end
  end
end