trends.rb 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # frozen_string_literal: true
  2. module Trends
  3. def self.table_name_prefix
  4. 'trends_'
  5. end
  6. def self.links
  7. @links ||= Trends::Links.new
  8. end
  9. def self.tags
  10. @tags ||= Trends::Tags.new
  11. end
  12. def self.statuses
  13. @statuses ||= Trends::Statuses.new
  14. end
  15. def self.register!(status)
  16. [links, tags, statuses].each { |trend_type| trend_type.register(status) }
  17. end
  18. def self.refresh!
  19. [links, tags, statuses].each(&:refresh)
  20. end
  21. def self.request_review!
  22. return unless enabled?
  23. links_requiring_review = links.request_review
  24. tags_requiring_review = tags.request_review
  25. statuses_requiring_review = statuses.request_review
  26. return if links_requiring_review.empty? && tags_requiring_review.empty? && statuses_requiring_review.empty?
  27. User.those_who_can(:manage_taxonomies).includes(:account).find_each do |user|
  28. AdminMailer.new_trends(user.account, links_requiring_review, tags_requiring_review, statuses_requiring_review).deliver_later! if user.allows_trends_review_emails?
  29. end
  30. end
  31. def self.enabled?
  32. Setting.trends
  33. end
  34. def self.available_locales
  35. @available_locales ||= I18n.available_locales.map { |locale| locale.to_s.split(/[_-]/).first }.uniq
  36. end
  37. end