custom_filter_keyword.rb 863 B

12345678910111213141516171819202122232425262728293031323334
  1. # frozen_string_literal: true
  2. # == Schema Information
  3. #
  4. # Table name: custom_filter_keywords
  5. #
  6. # id :bigint not null, primary key
  7. # custom_filter_id :bigint not null
  8. # keyword :text default(""), not null
  9. # whole_word :boolean default(TRUE), not null
  10. # created_at :datetime not null
  11. # updated_at :datetime not null
  12. #
  13. class CustomFilterKeyword < ApplicationRecord
  14. belongs_to :custom_filter
  15. validates :keyword, presence: true
  16. alias_attribute :phrase, :keyword
  17. before_save :prepare_cache_invalidation!
  18. before_destroy :prepare_cache_invalidation!
  19. after_commit :invalidate_cache!
  20. private
  21. def prepare_cache_invalidation!
  22. custom_filter.prepare_cache_invalidation!
  23. end
  24. def invalidate_cache!
  25. custom_filter.invalidate_cache!
  26. end
  27. end