Class: ValidatesStructure::Validator::KlassValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- ValidatesStructure::Validator::KlassValidator
- Defined in:
- lib/validates-structure.rb
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/validates-structure.rb', line 130 def validate_each(record, attribute, value) return if value.nil? klass = [:klass] if klass == Boolean unless value.is_a?(TrueClass) || value.is_a?(FalseClass) record.errors.add attribute, "has class \"#{value.class}\" but should be boolean" end elsif !(value.is_a?(klass)) record.errors.add attribute, "has class \"#{value.class}\" but should be a \"#{klass}\"" end end |