Replace =~ with #matches?. #208.
=~ made sense when we were passing it through to a regex, but we're no longer doing that: TagMatcher looks at individual tags and returns a value that *looks* like what you get out of #=~ but really isn't that meaningful. Probably a good idea to not subvert convention like this and instead use a name with guessable intent.
This commit is contained in:
@@ -174,19 +174,19 @@ class FeedManager
|
||||
text_matcher = Glitch::KeywordMute.text_matcher_for(receiver_id)
|
||||
tag_matcher = Glitch::KeywordMute.tag_matcher_for(receiver_id)
|
||||
|
||||
should_filter = text_matcher =~ status.text
|
||||
should_filter ||= text_matcher =~ status.spoiler_text
|
||||
should_filter ||= tag_matcher =~ status.tags
|
||||
should_filter = text_matcher.matches?(status.text)
|
||||
should_filter ||= text_matcher.matches?(status.spoiler_text)
|
||||
should_filter ||= tag_matcher.matches?(status.tags)
|
||||
|
||||
if status.reblog?
|
||||
reblog = status.reblog
|
||||
|
||||
should_filter ||= text_matcher =~ reblog.text
|
||||
should_filter ||= text_matcher =~ reblog.spoiler_text
|
||||
should_filter ||= tag_matcher =~ status.tags
|
||||
should_filter ||= text_matcher.matches?(reblog.text)
|
||||
should_filter ||= text_matcher.matches?(reblog.spoiler_text)
|
||||
should_filter ||= tag_matcher.matches?(status.tags)
|
||||
end
|
||||
|
||||
!!should_filter
|
||||
should_filter
|
||||
end
|
||||
|
||||
def filter_from_mentions?(status, receiver_id)
|
||||
|
@@ -62,8 +62,8 @@ class Glitch::KeywordMute < ApplicationRecord
|
||||
format('keyword_mutes:regex:text:%s', account_id)
|
||||
end
|
||||
|
||||
def =~(str)
|
||||
regex =~ str
|
||||
def matches?(str)
|
||||
!!(regex =~ str)
|
||||
end
|
||||
|
||||
private
|
||||
@@ -82,8 +82,8 @@ class Glitch::KeywordMute < ApplicationRecord
|
||||
format('keyword_mutes:regex:tag:%s', account_id)
|
||||
end
|
||||
|
||||
def =~(tags)
|
||||
tags.pluck(:name).detect { |n| regex =~ n }
|
||||
def matches?(tags)
|
||||
tags.pluck(:name).any? { |n| regex =~ n }
|
||||
end
|
||||
|
||||
private
|
||||
|
Reference in New Issue
Block a user