Class: BoardProjectRecentVisit

Inherits:
ApplicationRecord show all
Defined in:
app/models/board_project_recent_visit.rb

Overview

Tracks which boards in a specific project a user has visited

Class Method Summary collapse

Methods inherited from ApplicationRecord

at_most, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, underscore, without_order

Class Method Details

.latest(user, project, count: nil) ⇒ Object


22
23
24
25
26
27
# File 'app/models/board_project_recent_visit.rb', line 22

def self.latest(user, project, count: nil)
  visits = by_user_project(user, project).order(updated_at: :desc)
  visits = visits.preload(:board) if count && count > 1

  visits.first(count)
end

.visited!(user, board) ⇒ Object


15
16
17
18
19
20
# File 'app/models/board_project_recent_visit.rb', line 15

def self.visited!(user, board)
  visit = find_or_create_by(user: user, project: board.project, board: board)
  visit.touch if visit.updated_at < Time.current
rescue ActiveRecord::RecordNotUnique
  retry
end