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