Sha256: c496bad194365cc75dfa3714ad267fc1bf07bc86a4917f157b7ca06726417955
Contents?: true
Size: 696 Bytes
Versions: 4
Compression:
Stored size: 696 Bytes
Contents
require "active_model" module SwifterEnum class SwifterEnumValidator < ActiveModel::EachValidator def validate_each(record, attribute, a_value) if !a_value.is_a?(SwifterEnum::Base) || a_value.instance_of?(SwifterEnum::Base) record.errors.add(attribute, "#{a_value.value} is not a valid subclass of SwifterEnum") end if a_value.value.nil? return if options[:allow_nil] record.errors.add(attribute, "nil value for #{attribute} is not allowed") end unless a_value.class.values.key?(a_value.value) # binding.b record.errors.add(attribute, "#{a_value.value} is not a valid #{attribute} type") end end end end
Version data entries
4 entries across 4 versions & 1 rubygems