summaryrefslogtreecommitdiff
path: root/app/controllers/concerns/find_snippet.rb
blob: 8a4adbb608f04d033208c3a6b8cec4c056f78fd2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# frozen_string_literal: true

module FindSnippet
  extend ActiveSupport::Concern
  include Gitlab::Utils::StrongMemoize

  private

  # rubocop:disable CodeReuse/ActiveRecord
  def snippet
    strong_memoize(:snippet) do
      snippet_klass.inc_relations_for_view.find_by(snippet_find_params)
    end
  end
  # rubocop:enable CodeReuse/ActiveRecord

  def snippet_klass
    raise NotImplementedError
  end

  def snippet_id
    params[:id]
  end

  def snippet_find_params
    { id: snippet_id }
  end
end