2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-06-28 16:56:44 -04:00
|
|
|
class WatchedWordListSerializer < ApplicationSerializer
|
2019-08-02 05:53:03 -04:00
|
|
|
attributes :actions, :words, :regular_expressions, :compiled_regular_expressions
|
2017-06-28 16:56:44 -04:00
|
|
|
|
|
|
|
def actions
|
|
|
|
WatchedWord.actions.keys
|
|
|
|
end
|
|
|
|
|
|
|
|
def words
|
|
|
|
object.map do |word|
|
|
|
|
WatchedWordSerializer.new(word, root: false)
|
|
|
|
end
|
|
|
|
end
|
2017-09-27 15:48:57 -04:00
|
|
|
|
|
|
|
# No point making this site setting `client: true` when it's only used
|
|
|
|
# in the admin section
|
|
|
|
def regular_expressions
|
|
|
|
SiteSetting.watched_words_regular_expressions?
|
|
|
|
end
|
2019-08-02 05:53:03 -04:00
|
|
|
|
|
|
|
def compiled_regular_expressions
|
|
|
|
expressions = {}
|
|
|
|
WatchedWord.actions.keys.each do |action|
|
|
|
|
expressions[action] = WordWatcher.word_matcher_regexp(action)&.source
|
|
|
|
end
|
|
|
|
expressions
|
|
|
|
end
|
2017-06-28 16:56:44 -04:00
|
|
|
end
|