trends.rb 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 if skip_review? || !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.with(recipient: user.account).new_trends(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.skip_review?
  35. Setting.trendable_by_default
  36. end
  37. def self.available_locales
  38. @available_locales ||= I18n.available_locales.map { |locale| locale.to_s.split(/[_-]/).first }.uniq
  39. end
  40. end