Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. # frozen_string_literal: true
  2.  
  3. #
  4. # Devise & ActsAsTaggableOn gems combination
  5. # This fix redefine inspect method by excluding tag_lists form it.
  6. #
  7. # Because the way Devise redefines inspect method tag_lists are getting
  8. # loaded on every user query.
  9. #
  10. # From Devise:
  11. #
  12. # Redefine serializable_hash in models for more secure defaults.
  13. # By default, it removes from the serializable model all attributes that
  14. # are *not* accessible. You can remove this default by using :force_except
  15. # and passing a new list of attributes you want to exempt. All attributes
  16. # given to :except will simply add names to exempt to Devise internal list.
  17. #
  18. # Redefine inspect using serializable_hash, to ensure we don't accidentally
  19. # leak passwords into exceptions.
  20. #
  21. module DeviseTagsFix
  22. def inspect
  23. inspection = serializable_hash(except: tag_lists).collect do |k, v|
  24. "#{k}: #{respond_to?(:attribute_for_inspect) ? attribute_for_inspect(k) : v.inspect}"
  25. end
  26. "#<#{self.class} #{inspection.join(', ')}>"
  27. end
  28.  
  29. def tag_lists
  30. self.class.tag_types.map { |type| "#{type.to_s.singularize}_list" }
  31. end
  32. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement