Class: UnitValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- UnitValidator
- Defined in:
- lib/unit_validation.rb
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/unit_validation.rb', line 3 def validate_each(record, attribute, value) allowed=Array([:allowed_types]) if [:allowed_types] begin v=Unit.new(value) if allowed unless allowed.include?(v.kind) record.errors[attribute] << ([:message] || "is not a valid unit of #{allowed.collect(&:to_s).join(',')}") end end rescue record.errors[attribute] << ([:message] || "is not a valid measurement") end end |