Welcome to mirror list, hosted at ThFree Co, Russian Federation.

optionally_search.rb « concerns « models « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9d43c61eb57ea11e410314928857f62d14803aa1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# frozen_string_literal: true

module OptionallySearch
  extend ActiveSupport::Concern

  class_methods do
    def search(query, **options)
      raise(
        NotImplementedError,
        'Your model must implement the "search" class method'
      )
    end

    # Optionally limits a result set to those matching the given search query.
    def optionally_search(query = nil, **options)
      query.present? ? search(query, **options) : all
    end
  end
end