Advertisement
Guest User

Untitled

a guest
Feb 13th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. module Virtus
  2. class Attribute
  3.  
  4. # Attribute extension which nullifies blank attributes when coercion failed
  5. #
  6. module NullifyBlank
  7.  
  8. # @see [Attribute#coerce]
  9. #
  10. # @api public
  11. def coerce(input)
  12. output = super
  13.  
  14. if !value_coerced?(output) && input.blank?
  15. nil
  16. # Added to nullify anything that is blank not just strings.
  17. elsif output.blank?
  18. nil
  19. else
  20. output
  21. end
  22. end
  23.  
  24. end # NullifyBlank
  25.  
  26. end # Attribute
  27. end # Virtus
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement