Guest User

Untitled

a guest
Apr 21st, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. class EmailTemplate < ActiveRecord::Base
  2. TEXT_PLAIN = 1
  3. TEXT_HTML = 2
  4. BOTH = TEXT_PLAIN | TEXT_HTML
  5.  
  6. def after_initialize
  7. if new_record?
  8. self.content_types ||= BOTH
  9. end
  10. end
  11.  
  12. def plain_text?
  13. (content_types & TEXT_PLAIN) ? true : false
  14. end
  15.  
  16. def plain_text=(v)
  17. content_types ^= TEXT_PLAIN if v ^ plain_text?
  18. end
  19.  
  20. def html?
  21. (content_types & TEXT_HTML) ? true : false
  22. end
  23.  
  24. def html=(v)
  25. content_types ^= TEXT_HTML if v ^ html?
  26. end
  27.  
  28. def formats
  29. returning [] do |a|
  30. a << 'text/plain' if content_types & TEXT_PLAIN
  31. a << 'text/html' if content_types & TEXT_HTML
  32. end
  33. end
  34. end
Add Comment
Please, Sign In to add comment