debian-mirror-gitlab/app/models/concerns/board_recent_visit.rb

35 lines
706 B
Ruby
Raw Normal View History

2021-06-08 01:23:25 +05:30
# frozen_string_literal: true
module BoardRecentVisit
extend ActiveSupport::Concern
class_methods do
def visited!(user, board)
find_or_create_by(
"user" => user,
board_parent_relation => board.resource_parent,
board_relation => board
).tap do |visit|
visit.touch
end
rescue ActiveRecord::RecordNotUnique
retry
end
def latest(user, parent, count: nil)
visits = by_user_parent(user, parent).order(updated_at: :desc)
visits = visits.preload(board_relation)
visits.first(count)
end
def board_relation
:board
end
def board_parent_relation
raise NotImplementedError
end
end
end