2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-06-28 16:56:44 -04:00
|
|
|
class WatchedWordListSerializer < ApplicationSerializer
|
2021-05-27 12:20:26 -04:00
|
|
|
attributes :actions, :words, :compiled_regular_expressions
|
2017-06-28 16:56:44 -04:00
|
|
|
|
|
|
|
def actions
|
2021-05-14 09:52:10 -04:00
|
|
|
SiteSetting.tagging_enabled ? WatchedWord.actions.keys
|
|
|
|
: WatchedWord.actions.keys.filter { |k| k != :tag }
|
2017-06-28 16:56:44 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def words
|
|
|
|
object.map do |word|
|
|
|
|
WatchedWordSerializer.new(word, root: false)
|
|
|
|
end
|
|
|
|
end
|
2017-09-27 15:48:57 -04:00
|
|
|
|
2019-08-02 05:53:03 -04:00
|
|
|
def compiled_regular_expressions
|
|
|
|
expressions = {}
|
2021-05-14 09:52:10 -04:00
|
|
|
actions.each do |action|
|
2019-08-02 05:53:03 -04:00
|
|
|
expressions[action] = WordWatcher.word_matcher_regexp(action)&.source
|
|
|
|
end
|
|
|
|
expressions
|
|
|
|
end
|
2017-06-28 16:56:44 -04:00
|
|
|
end
|