Class: Volt::TypeValidator
- Defined in:
- lib/volt/models/validators/type_validator.rb
Class Method Summary collapse
Class Method Details
.validate(model, field_name, args) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/volt/models/validators/type_validator.rb', line 4 def self.validate(model, field_name, args) errors = {} value = model.get(field_name) type_restriction = args.is_a?(Hash) ? args[:type] : args unless value.is_a?(type_restriction) if args.is_a?(Hash) && args[:message] = args[:message] else = "must be of type #{type_restriction.to_s}" end errors[field_name] = [] end errors end |