Sha256: 331e48c2b79c646d8a902a8b01f0660a80edae1dcca91f2346170a928fc133e2

Contents?: true

Size: 316 Bytes

Versions: 2

Compression:

Stored size: 316 Bytes

Contents

require 'active_model'

class TypeValidator < ActiveModel::EachValidator
  def options
    super.merge(allow_nil: true)
  end

  def validate_each(record, attribute, value)
    unless value.is_a?(options[:with])
      record.errors.add(attribute, "must be a #{options[:with]}, not #{value.class}")
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
minarai-0.0.2 lib/validator/type_validator.rb
minarai-0.0.1 lib/validator/type_validator.rb