Class: Trackguard::BlockedPath

Inherits:
ApplicationRecord
  • Object
show all
Defined in:
app/models/trackguard/blocked_path.rb

Constant Summary collapse

CACHE_KEY =
"trackguard/blocked_path_patterns"

Class Method Summary collapse

Class Method Details

.blocked?(path) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
# File 'app/models/trackguard/blocked_path.rb', line 11

def self.blocked?(path)
  patterns = Rails.cache.fetch(CACHE_KEY, expires_in: 10.minutes) do
    pluck(:pattern)
  end
  patterns.any? { |p| path.to_s.downcase.include?(p.downcase) }
end

.matching_pattern(path) ⇒ Object



18
19
20
21
22
23
# File 'app/models/trackguard/blocked_path.rb', line 18

def self.matching_pattern(path)
  patterns = Rails.cache.fetch(CACHE_KEY, expires_in: 10.minutes) do
    pluck(:pattern)
  end
  patterns.find { |p| path.to_s.downcase.include?(p.downcase) }
end