status_pin.rb 781 B

123456789101112131415161718192021222324252627282930313233
  1. # frozen_string_literal: true
  2. # == Schema Information
  3. #
  4. # Table name: status_pins
  5. #
  6. # id :bigint(8) not null, primary key
  7. # account_id :bigint(8) not null
  8. # status_id :bigint(8) not null
  9. # created_at :datetime not null
  10. # updated_at :datetime not null
  11. #
  12. class StatusPin < ApplicationRecord
  13. belongs_to :account
  14. belongs_to :status
  15. validates_with StatusPinValidator
  16. after_destroy :invalidate_cleanup_info, if: %i(account_matches_status_account? account_local?)
  17. delegate :local?, to: :account, prefix: true
  18. private
  19. def invalidate_cleanup_info
  20. account.statuses_cleanup_policy&.invalidate_last_inspected(status, :unpin)
  21. end
  22. def account_matches_status_account?
  23. status&.account_id == account_id
  24. end
  25. end