Sha256: 7d2f1775cc54c3e18c0b4a3f231837c612f2d8aef9c1def1b01d9b558fccdbfc

Contents?: true

Size: 422 Bytes

Versions: 1

Compression:

Stored size: 422 Bytes

Contents

# frozen_string_literal: true

require 'active_model'

class TypeValidator
  class KindOf
    def self.invalid?(record, attribute, value, options)
      types = Array(options[:is_a] || options[:kind_of])
      allow_nil = options[:allow_nil]

      return if (allow_nil && value.nil?) || types.any? { |type| value.is_a?(type) }

      "must be a kind of: #{types.map { |klass| klass.name }.join(', ')}"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
type_validator-0.2.0 lib/type_validator/kind_of.rb