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
|
|
|
if SiteSetting.tagging_enabled
|
|
|
|
WatchedWord.actions.keys
|
2023-01-09 06:20:10 -06:00
|
|
|
else
|
2021-05-14 08:52:10 -05:00
|
|
|
WatchedWord.actions.keys.filter { |k| k != :tag }
|
2023-01-09 06:20:10 -06:00
|
|
|
end
|
2017-06-28 15:56:44 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def words
|
|
|
|
object.map { |word| WatchedWordSerializer.new(word, root: false) }
|
|
|
|
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
|