Guest User

Untitled

a guest
Apr 23rd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. class Product < ActiveRecord::Base
  2.  
  3. ...
  4.  
  5. # Sustainability Flags
  6. RECYCLED_BIT = 1 << 0
  7. RECYCLEABLE_BIT = 1 << 1
  8. BIODEGRADABLE_BIT = 1 << 2
  9. LOCAL_BIT = 1 << 3
  10.  
  11. def recycled?
  12. (flags & RECYCLED_BIT) != 0
  13. end
  14.  
  15. def recycled=(flag)
  16. if flag
  17. write_attribute("flags", flags | RECYCLED_BIT)
  18. else
  19. write_attribute("flags", flags & ~RECYCLED_BIT)
  20. end
  21. end
  22.  
  23. def recyclable?
  24. (flags & RECYCLABLE_BIT) != 0
  25. end
  26.  
  27. def recyclable=(flag)
  28. if flag
  29. write_attribute("flags", flags | RECYCLABLE_BIT)
  30. else
  31. write_attribute("flags", flags & ~RECYCLABLE_BIT)
  32. end
  33. end
  34.  
  35. def biodegradable?
  36. (flags & BIODEGRADABLE_BIT) != 0
  37. end
  38.  
  39. def biodegradable=(flag)
  40. if flag
  41. write_attribute("flags", flags | BIODEGRADABLE_BIT)
  42. else
  43. write_attribute("flags", flags & ~BIODEGRADABLE_BIT)
  44. end
  45. end
  46.  
  47. def local?
  48. (flags & LOCAL_BIT) != 0
  49. end
  50.  
  51. def local=(flag)
  52. if flag
  53. write_attribute("flags", flags | LOCAL_BIT)
  54. else
  55. write_attribute("flags", flags & ~LOCAL_BIT)
  56. end
  57. end
  58.  
  59. ...
  60.  
  61. end
Add Comment
Please, Sign In to add comment