Sha256: fab37d0f2279b812e5a1ea75462be2dcfed44a118f5f17440b8b3a4f1f1c3cf5
Contents?: true
Size: 417 Bytes
Versions: 3
Compression:
Stored size: 417 Bytes
Contents
# frozen_string_literal: true class InstanceOfValidator < ActiveModel::EachValidator def validate_each(obj, attribute, value) with_option = Array.wrap(options[:with] || options[:in]) return if with_option.any? { |type| value.instance_of?(type) } expectation = with_option.map(&:name).join(" | ") obj.errors.add(attribute, (options[:message] || "is not an instance of #{expectation}")) end end
Version data entries
3 entries across 3 versions & 1 rubygems