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
|
2023-01-09 06:20:10 -06:00
|
|
|
if SiteSetting.tagging_enabled
|
|
|
|
WatchedWord.actions.keys
|
|
|
|
else
|
|
|
|
WatchedWord.actions.keys.filter { |k| k != :tag }
|
|
|
|
end
|
2017-06-28 15:56:44 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def words
|
2023-01-09 06:20:10 -06:00
|
|
|
object.map { |word| WatchedWordSerializer.new(word, root: false) }
|
2017-06-28 15:56:44 -05:00
|
|
|
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|
|
2023-11-01 09:41:10 -05:00
|
|
|
expressions[action] = WordWatcher.serialized_regexps_for_action(action, engine: :js)
|
2019-08-02 04:53:03 -05:00
|
|
|
end
|
|
|
|
expressions
|
|
|
|
end
|
2017-06-28 15:56:44 -05:00
|
|
|
end
|