Sha256: bd50a24d13497078d9c8bdb8aea3cf3e3dbe8eef370fbaf9c96d5bb4040a9bcc
Contents?: true
Size: 659 Bytes
Versions: 6
Compression:
Stored size: 659 Bytes
Contents
module Zermelo module Records class TypeValidator < ActiveModel::Validator def validate(record) attr_types = record.class.attribute_types attr_types.each_pair do |name, type| value = record.send(name) next if value.nil? valid_type = Zermelo::ALL_TYPES[type] unless valid_type.any? {|type| value.is_a?(type) } count = (valid_type.size > 1) ? 'one of ' : '' type_str = valid_type.collect {|type| type.name }.join(", ") record.errors.add(name, "should be #{count}#{type_str} but is #{value.class.name}") end end end end end end
Version data entries
6 entries across 6 versions & 1 rubygems